Skip to content
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

pdf_from_url CSS not working #1104

Open
veeKewl opened this issue Feb 22, 2024 · 1 comment
Open

pdf_from_url CSS not working #1104

veeKewl opened this issue Feb 22, 2024 · 1 comment

Comments

@veeKewl
Copy link

veeKewl commented Feb 22, 2024

Im using the WickedPdf.new.pdf_from_url and whatever i do it always generate a file with almost no CSS honored.

This is the sample using "https://github.com/mileszs/wicked_pdf" as url
image

@unixmonkey
Copy link
Collaborator

The output here is exactly the same as if you ran wkhtmltopdf https://github.com/mileszs/wicked_pdf/ out.pdf.

For example if you run wkhtmltopdf https://csszengarden.com/221/ out.pdf, you'll see plenty of colors and CSS being applied, because the CSS it uses is more compatible with an older browser engine.

I think the real problem isn't that the CSS styling isn't being applied, but it's that the CSS engine inside of wkhtmltopdf is too old to understand the CSS that GitHub currently serves up. I don't blame GitHub. Most people browsing code have up-to-date browsers, and they can save bandwidth by using modern CSS, HTML, & JS.

wkhtmltopdf is based off an early version of Chrome's webkit, circa 2013, which only barely supported early HTML5, and some ES2015 JS, and no CSS3 that I know of. When Chrome stopped contributing to the open-source effort, the engine behind wkhtmltopdf stopped getting updates, even though the code kept being maintained to fix mostly non-rendering-engine issues. Chrome kept getting updated, but the open-source fork of webkit did not.

Recently, the wkhtmltopdf project has shut down entirely. This project will always work for people already using it, and those writing their HTML, CSS, & JS in an older way, but for new projects, you should consider an alternative, like Headless Chrome with Puppeteer for more modern support.

You can find more on this and a bunch of alternatives in this issue: #1081

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants