by SigmundA · 5y ago · 0 comments
In the meantime Chrome added headless support and with command line or puppeteer you can do the same thing with a much newer and more secure engine.
However if you need full CSS-Paged support then PrinceXML is probably your only option and its not cheap: https://www.princexml.com
There are reliability problems with wkhtmltopdf, but it's possible to make it reasonably reliable with enough error detection and retrying.
So, it would become fairly inaccurate using wkhtmltopdf.
It would look like either the entire item had no issues, or it had sustained damage everywhere.
Basically prince adds a watermark on the first page - so you do all your revisions and then only pay for the final copy to remove the watermark (however as any editor would know, we always have many final, final final, final v3 versions ;) so paying for prince once-off at 500$ is probably the best way for anyone who needs professional pdfing.
I wrote a latex / markdown / html editor with a simple mechanism (using the browsers default print settings), I think it’s not too bad for those looking to pdf from html:
Issue with mine is you would have to do all style sheets in line. I would recommend serious users to either pay for Prince if they want header/footer/page number control or just use print style sheets and code the html / css themselves and use headless chrome or chrome itself to print. Many people want JavaScript in their pages, I can’t recall if headless chrome can correctly account for that. File > print is the best imo :)
Yep, this is the way to go now. Very simple API with puppeteer and everything looks the same as when viewing the page in a browser (save any @media print css).
I already tried to fill in a bug: https://bugs.chromium.org/p/chromium/issues/detail?id=953313... but the spec is not very clear nor requires the most compact arrangement possible. It would probably be a worthy addition to the spec even just for the environmental impact (limiting number of pages when printing).
I like the functionality from Chrome to use it headless, but my main problem with it is that text is not selectable in the rendered PDF. It seems to be an screencapture as image or something. Anyone has this working? Selectable text is really needed for generating PDF invoices.
Here is reproducible demo that is selectable and clickable (links):
- https://majkinetor.github.io/mm-docs-template/docs.pdf
This is done using puppetear.
The same can be achieved by Save as PDF in chrome of single page containing entire site:
- https://majkinetor.github.io/mm-docs-template/print_page/
This is all part of my mm-docs framework:
I just tried printing the Hacker News front page to PDF in Edge which is the same engine as Chrome and the text was selectable.
Source: working on automatic PDF reporting in my current company.