pdfparser
pdfparser copied to clipboard
PHP Fatal error: Uncaught TypeError: Return value of Smalot\PdfParser\Page::getPDFObjectForFpdf() must be an instance of Smalot\PdfParser\PDFObject, null returned in pdfparser/Page.php:277
Hello,
In the attached file I have added a specific document provided by a vendor: invoice.pdf
When I try to load the file in the pdfparser it throws following fatal error:
PHP Notice: Undefined offset: 0 in pdfparser/Page.php on line 277
PHP Fatal error: Uncaught TypeError: Return value of Smalot\PdfParser\Page::getPDFObjectForFpdf() must be an instance of Smalot\PdfParser\PDFObject, null returned in pdfparser/Page.php:277
Stack trace:
#0 pdfparser/Page.php(397): Smalot\PdfParser\Page->getPDFObjectForFpdf()
#1 pdfparser/Page.php(424): Smalot\PdfParser\Page->extractRawData()
#2 pdfparser/Page.php(502): Smalot\PdfParser\Page->extractDecodedRawData()
#3 pdfparser/Page.php(655): Smalot\PdfParser\Page->getDataCommands()
#4 /home/boyan/scripts/easy_php/pdfparser.php(12): Smalot\PdfParser\Page->getDataTm()
#5 {main}
thrown in pdfparser/Page.php on line 277
I don't have any details how the PDF is generated by our vendor. I have tried different hacks but without success. Is it possible someone more familiar with the project to take a look?
Hi, I have a look on this one.
I am not programming in PHP anymore, so I don't have the tools and time, in place right now to help on debugging this problem.
But I have a look on this, and the file was produced by FPDF but a old version of it (FPDF 1.53), but when the first fix/enhancement for working with FPDF was done, it was tested with FPDF 1.83.
I could give you a work around, and someone else could test it, made a better investigation and research and come back with a final fix for this, and of course follow all the step of testing needed for this final fix, that I don't have the time, right now.
Ok, the work around for this file is to go to the Smalot\PdfParser\Page.php
file and change the isFpdf
method, to return False if 'FPDF 1.53' is found
public function isFpdf(): bool
{
if (\array_key_exists('Producer', $this->document->getDetails()) &&
\is_string($this->document->getDetails()['Producer']) &&
str_starts_with($this->document->getDetails()['Producer'], 'FPDF 1.53')) {
return false;
}
if (\array_key_exists('Producer', $this->document->getDetails()) &&
\is_string($this->document->getDetails()['Producer']) &&
str_starts_with($this->document->getDetails()['Producer'], 'FPDF')) {
return true;
}
return false;
}
I Believe it should work. But I haven't done a full test on it, and as I said, I can't do more research on this right now. I hope this could help you.
By the way, it will required to see if there are a reason why the FPDF 1.53 is so different than the FPDF 1.83. Or is there are major changes between this two (or other) versions. This recommendation is for the person that make the final fix.