barryvdh / laravel-snappy

Laravel Snappy PDF
MIT License
2.63k stars 290 forks source link

Error when merging snappy created pdfs #448

Closed dhardy1988 closed 2 years ago

dhardy1988 commented 3 years ago

Hi, I am facing an issue with merging PDFs from within my tests.

I have a number of PDFs, stored in a local folder, I am scandir() -> loop through the PDFs and merge using a pdf merge package. this all works great on the front end application and I get a nice merged PDF

HOWEVER

when using PDF::fake() in my phpunit tests and then doing the same, looping through the pdfs in a folder and attempting to merge I am facing an error: The xref position points to an incorrect object type

The error is in the PDF created by snappy.

Can anyone please help me to understand what is going on and why?

Thanks

ghost commented 3 years ago

I encountered the same issue and the reason seems to be in the output provided by PdfFaker here: https://github.com/barryvdh/laravel-snappy/blob/1903ab84171072b6bff8d98eb58d38b2c9aaf645/src/PdfFaker.php#L174

The resulting PDF created here seems to have this xref issue, I solved this by creating a patch that replaces the outputted PDF with the minimal PDF found here: https://brendanzagaeski.appspot.com/0004.html

I could make a PR for this but I'm not sure what the status for this project is.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy. If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.