Laravel PDF merger not working properly with specific file

745 views Asked by At

I have an application running on Laravel 5.7. In this application we use lynx39/lara-pdf-merger which uses daltcore/lara-pdf-merger. We use this package to simply merge two pdf documents into one.

$basename = "merged_file.pdf";

$pdfMerger = PDFMerger::init();
$pdfMerger->addPDF( public_path($this->order->contractor_file), 'all' );
$pdfMerger->addPDF( public_path($this->docs_file), 'all' );
$pdfMerger->merge();
$pdfMerger->save( public_path("data/transports/$this->id/$basename") );

For a few months there has been no issue with this package, however a few days ago we had a problem merging two pdf files. Both pdf files are of version 1.6, first one contains 5 pages and second one 154 pages. The merged output file contained 5 pages from PDF no. 1 but only first 53 pages from PDF no. 2. I thought it could be because of size, but there was no problem when I tested it with another PDF with 150 pages. I saw that the second file did not have the same headers, so I thought it might be corrupted.

Afterwards, I tried to merge it on the ilovepdf website and it merged correctly, so I split it into separate and the new file was able to be merged without problems in my application.

Can anyone help me with what exactly is the problem in here and maybe what would be a solution or alternative?

1

There are 1 answers

0
Lukas Grofcik On BEST ANSWER

So there was no fix, and as @johnwhitington mentioned switching to another library is the only way, or for me at least. We decided to with https://github.com/Setasign/FPDI