Process Multiple Files
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.7k
- Forks
- 579
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
Hi,
I've got folder on the server with several pdf files (all of them using the same template). I've been trying hard to figure out how I could parse all of them in one run by PDF Parser, but PDF Parser just outputs data for the first file. It's like you are not allowed process one file and then continue with the next one in a foreach loop. I've tried to initiate a new instance of the Parser within the foreach for each file, also by reusing the same Parser for all files. Consider the following example where the Parser is initiated outside of the foreach. How would I go about processing all files at once?
My goal is to fetch data from several reports, union the data into a json object and use for import in other applications.
error_reporting(E_ALL);
ini_set("display_errors", 1);
include 'vendor/autoload.php';
$report_files = glob(dirname(FILE) .'/reports/*.pdf');
// Parse pdf file and build necessary objects.
$parser = new \Smalot\PdfParser\Parser();
foreach($report_files as $file)
{
// $parser = new \Smalot\PdfParser\Parser();
$pdf = $parser->parseFile($file);
// Retrieve all pages from the pdf file.
$pages = $pdf->getPages();
// Loop over each page to extract text.
foreach ($pages as $page)
{
echo $page->getText();
echo "<hr>";
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Parser usage shown in the issue, especially parseFile() inside the foreach over reports/*.pdf, and reproduce the behavior with several matching PDFs. Trace the parser state across iterations and verify that the completed behavior includes extracted output from every input file in the run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100