myokyawhtun / PDFMerger

PDFMerger compatible for PHP 5, PHP 7, and PHP 8
238 stars 272 forks source link

FATAL ERROR in tcpdi_parser.php - Includes fix detail. #53

Open RigidCollision opened 3 years ago

RigidCollision commented 3 years ago

Was recieving the following error on 'some' merge requests:

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, bool given in C:\MyPath\www\PDFMerger\tcpdf\tcpdi_parser.php:503 Stack trace: #0 C:\MyPath\www\PDFMerger\tcpdf\tcpdi_parser.php(373): tcpdi_parser->decodeXrefStream() #1 C:\MyPath\www\PDFMerger\tcpdf\tcpdi_parser.php(212): tcpdi_parser->getXrefData() #2 C:\MyPath\www\PDFMerger\tcpdf\tcpdi.php(121): tcpdi_parser->__construct() #3 C:\MyPath\www\PDFMerger\tcpdf\tcpdi.php(88): TCPDI->_getPdfParser() #4 C:\MyPath\www\PDFMerger\PDFMerger.php(97): TCPDI->setSourceFile() #5 C:\MyPath\www\offline downloads\download-DL100.php(75): PDFMerger\PDFMerger->merge() #6 {main} thrown in C:\MyPath\www\PDFMerger\tcpdf\tcpdi_parser.php on line 503

Line 503 is: } elseif (($key == '/Index') AND ($v[0] == PDF_TYPE_ARRAY AND count($v[1] >= 2))) {

Changed to: } elseif (($key == '/Index') AND ($v[0] == PDF_TYPE_ARRAY AND count($v[1]) >= 2)) {

Please verify this change and update the release accordingly if fit for purpose. :)

Courtsilius commented 2 years ago

Thank you so much! This helped me since I had issues with bigger PDF files (more than 100 pages).

Additionally to that I added a check before the "switch ($predictor) {" on line 375, basically just

if(Count($row)<=$i){continue;}

somewhat hacky, but it works in my case, so leaving this just in case someone else might stumble on this c:

Manitnelav commented 2 years ago

Thank you so much!! You saved my day!

RigidCollision commented 2 years ago

No Worries. This could do with being addressed in the code and made part of a release?

RigidCollision commented 2 years ago

No problem, glad it helped you. Spencer

Sent from my iPhone

On 23 Sep 2022, at 09:50, Valentina Migliorato @.***> wrote:

 Thank you so much!! You saved my day!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.