ErrorException Undefined array key 38
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.7k
- Forks
- 579
- Avg merge
- 2m
- Merged PRs (30d)
- 1
Description
- PHP Version: 8.1
- PDFParser Version: "smalot/pdfparser": "2.7.0"
Description:
I'm getting an error when trying to run getDataTm() on a pdf. I have tried this on a native LAMP stack and inside a Symfony 6.3.6 framework.
ErrorException - Undefined array key 38
PDF input
Expected output & actual output
Code
$parser = new Parser();
$pdf = $parser->parseFile($uploadedFile);
$totalPages = $pdf->getDetails()['Pages'];
for ($p = 0; $p < $totalPages; $p++) {
**$data[$p] = $pdf->getPages()[$p]->getDataTm(); // <---- error happen here**
}
I temporary solved wrapping the read of array "$extractedTexts" in a "array_key_exists()" checking and all pdf texts seems correctly retrivied except for last text in the bottom right:"Page 1 of n" that is lost.
In "vendor/smalot/pdfparser/src/Smalot/PdfParser/Page.php":
Before fix:
704 $currentText = $extractedTexts[\count($extractedData)];
705 switch ($command['o']) {
After fix:
704 if (array_key_exists(\count($extractedData), $extractedTexts)) {
705 $currentText = $extractedTexts[\count($extractedData)];
706 switch ($command['o']) {
. . .
878 }
879 }
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 in src/Smalot/PdfParser/Page.php around line 704, then reproduce getDataTm() with the attached PDF and the reported PHP 8.1 setup. Trace how extractedTexts and extractedData are indexed during parsing. Done means the PDF parses without an undefined array key and the bottom-right “Page 1 of n” text is not lost.
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
- 45/100