myokyawhtun / PDFMerger

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

PDF 1.5 merge problems, php 8.1 #61

Closed miguelangelss4 closed 1 year ago

miguelangelss4 commented 2 years ago

Hello, I'm having issues wit pdf files that are working with 1.5 of pdf. Theese files worked with the original pdf merger by Jarrod Nettles, but I need it in newer PHP version.

require_once 'lib/PDFMergerPHP8/PDFMerger.php';
use PDFMerger\PDFMerger;

mezclarPDF();

function mezclarPDF(){
    $pdf = new PDFMerger;
    $pdf->addPDF(_ROOT_DIR_ . '\\pdf_inputs\\Personajes_TXT.pdf');
    //$pdf->addPDF(_ROOT_DIR_ . '\\pdf_inputs\\PedidoPDF.pdf');
    //$pdf->addPDF(_ROOT_DIR_ . '\\pdf_inputs\\PedidoPDFOld.pdf');
    $pdf->merge('browser', _ROOT_DIR_ . '\\pdf_outputs\\Personajes_TXT.pdf');
}

Personajes_TXT.pdf is the only file that works fine. The other ones, fails in lib\PDFMerger\tcpdf\tcpdi.php 503line: } elseif (($key == '/Index') AND ($v[0] == PDF_TYPE_ARRAY AND count($v[1] >= 2))) {

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

because php crashed by passing bool to count() function (seems like parenthesis typo mistake in the lib). But after this change, the lib only blocks itself, by consuming all memory available.

mehistaken commented 1 year ago

Just ran into this issue updating to PHP8.1. Changing the count() parentheses fixed the issue for me, didn't lock up anything.

miguelangelss4 commented 1 year ago

I don't continue with this project. PDFMerger gived me a lot of errors in php 8.1 so I decided develop this project in c# with net core