Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

AggelosGalatis's avatar

Merge PDF files above version 1.4 in Laravel 8

Does anyone know any package that can help me?

0 likes
14 replies
AggelosGalatis's avatar

Hello.

First of all thank you for your answer.

I use this package but i get the following error message when i try to merge my files:

fopen(C:\Users\User\Source\project\storage\tmp/4hN11SZYqdHrpdsm.pdf): Failed to open stream: No such file or directory

I think it can't find the merged pdf in storage\tmp folder because i get the error in merge(). Bellow is my code:

$mergedInvoiceLieferscheinPDF = \PDFMerger::init(); foreach($documents as $document) { $mergedInvoiceLieferscheinPDF->addPathToPDF(base_path($document), 'all', 'P'); $mergedInvoiceLieferscheinPDF->merge(); $mergedInvoiceLieferscheinPDF->save(base_path('/storage/tmp/merged_result.pdf')); }

1 like
vincent15000's avatar

@AggelosGalatis Have you checked in the directory if the file exists ? The error message says that the 4hN11SZYqdHrpdsm.pdf file does not exist, if it does not exist, you can't merge it.

AggelosGalatis's avatar

@vincent15000 Yes, my pdf files there are in the /storage/app/ folder. But i don't have any pdf file with this name. Also i notice that the error happens when it tries to execute the merge function.

1 like
vincent15000's avatar

@AggelosGalatis Not at all ... what I try to tell you is that your code tries to open a file in the tmp folder and you tell me that your pdf files are in the app folder. So why are you trying to open a pdf file from the tmp folder if your pdf files are in the app folder ? It has no sense ... ;).

AggelosGalatis's avatar

@vincent15000 I think it can't find the file because when i run the following command i get a different name for my pdf files.

$mergedPDF->addPathToPDF(base_path($document), 'all', 'P');

1 like
AggelosGalatis's avatar

@vincent15000 I used the same code for a pdf with version 1.4 and it worked. But for pdf above 1.4 it doesn't work. Maybe the problem is when it tries to convert the pdf file. I already installed ghostscript.

1 like
AggelosGalatis's avatar
AggelosGalatis
OP
Best Answer
Level 1

I found the problem. When i was trying to downgrade the PDF file, the new PDF file it was in a different folder, so the problem was the path, that's why the merge command couldn't find the file in tmp folder.

Please or to participate in this conversation.