spatie / laravel-pdf

Create PDF files in Laravel apps
https://spatie.be/docs/laravel-pdf
MIT License
681 stars 53 forks source link

[Bug]: Can't preview PDF in browser #171

Closed Fradd747 closed 3 weeks ago

Fradd747 commented 1 month ago

What happened?

I can't preview a PDF in browser using return pdf()->view('invoice')->name('filename.pdf');. It loads the PDF but it says "Failed to load PDF document." ->download() also works, although the file cannot be preview. It says again "Failed to load PDF document."

Seems like the headers are okay, but actual PDF file is corrupted.

image

How to reproduce the bug

Package Version

1.5.2

PHP Version

8.2.12

Laravel Version

11.20.0

Which operating systems does with happen with?

Windows

Notes

No response

tasso85 commented 1 month ago

I am having a very similar issue, which arised when I upgraded to puppeteer 22 to 23.

With version 22, it worked correctly.

Out of curiosity, which version of puppeteer are you using?

Fradd747 commented 1 month ago

You're right. I'm currently using puppeteer version 23.1.0 but when I downgraded to 22.15.0 it started working. Thank you.

tasso85 commented 1 month ago

You're welcome; however, this seems to confirm that there is some compatibility issue with the new version.

I tried diagnosing it, but to no avail, as it seems there is no log whatsoever; or maybe logging must be somehow "enabled", but I wouldn't know how to.

MariusMez commented 1 month ago

Indeed, related discussion here: https://github.com/spatie/browsershot/discussions/866

Currently with puppeteer >=23 PDF generation seems only working when using save() method.

JeppeKnockaert commented 3 weeks ago

Proposed a new fix here: https://github.com/spatie/browsershot/pull/876