-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOMPDF does not work with Sail? #3379
Comments
Happy to try to help but I use none of the cited frameworks, so 😬. I guess my first question is, what is the actual URL of the stylesheet when using sail vs lando? Seems like if that's the main difference then maybe Dompdf is unable to access that URL (for reasons). Could be that localhost is blocked somehow? Or maybe it's redirected (latest release of Dompdf doesn't follow redirects). You can try enabling additional debug logging for Dompdf itself. That may provide some information on why the stylesheet request is failing. |
I'm using Laravel DOMPDF, a wrapper for your package to make it easy to implement in a Laravel project. Laravel Sail is the current recommended way of setting up a Laravel local dev environment, at least if you're not using macOS, and it uses Docker containers to run all the PHP stuff. It uses Vite under the hood to build compiled versions of stylesheets and JavaScript files.
When I set So the stylesheet's URL, for example, is Lando uses the same paths, the only difference is the domain, which is
As far as I can tell, localhost isn't blocked because I can access the stylesheet and image URLs directly without any problems. I also don't see them redirecting anywhere else.
Perhaps it's because I'm using Laravel DOMPDF, but adding the code on that page under Configuration doesn't help. It gives me a bunch of PDF code (I think) that I cannot understand:
|
I'd say maybe remote resources aren't allowed, but then nexus.lndo.site also would not work. so presumably you are allowing remote resources somewhere ( Block could be at the PHP level (thus your ability to access via browser but Dompdf failing). I don't think this is what's happening, but you can confirm by setting up a simple script within the application that just fetches the file:
Yes, that is the PDF source. Laravel seems to be giving you fairly details messaging so maybe this isn't necessary. Somebody with more experience with debugging Dompdf in Laravel would have to help us here. |
Working with Tighten, a highly knowledgeable team of Laravel professionals, I finally have an answer. I needed to set |
That is not something I would have thought of. Thanks for providing your resolution. |
I have a project using Laravel 10 and Lando for a local dev environment. We recently implemented Laravel DOMPDF to turn a Blade template into a PDF.
This has been working fine, so long as we run
lando npm run build
rather thanlando npm run dev
so that it builds the stylesheet file in the correct directory and Vite links to the correct file.Now, I have implemented Laravel Sail, which also uses Vite, for our local dev environment as an alternative to Lando. It works perfectly except for Laravel DOMPDF. It seems unable to find the linked stylesheets and images, so the resulting PDF is unstyled and missing all the images.
Nothing has changed in the vite.config.js file, and the only thing I changed in .env is altering
APP_URL=http://nexus.lndo.site/
toAPP_URL=http://localhost/
.Here's the vite.config.js file:
And here is a snippet of the
dispatch-sheet.blade.php
file that is used for the PDF rendering.Here is a comparison of the outputs.
Lando:
Sail:
My guess is that Sail is doing something different when using Vite to compile the CSS file, specifically using a path different from Lando's. What could that be?
The text was updated successfully, but these errors were encountered: