Live data from Hacker News

Ask HN: What is nowadays (opensource) way of converting HTML to PDF?

news.ycombinator.com

61–70 of 170 posts

Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?

#61

I'd love to go the other way: convert a PDF into a self contained HTML page that renders properly in a browser. It's been way harder than I thought it would. Any advice?

> renders properly

Depending on your requirements on both PDF input and HTML output, there is often no way to do this that is both easy and general. At it's core, PDFs are not designed to be universally reflowable.

Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?

#63

I'd love to go the other way: convert a PDF into a self contained HTML page that renders properly in a browser. It's been way harder than I thought it would. Any advice?

You could embed it as a base64 blob, embed PDF.js (which is included by browsers anyway, I think) and use that to render it in the HTML. But I realize you probably meant a static HTML without JavaScript.

Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?

#66

openhtmltopdf is what we're using. Some outdated versions.

Been using this as well. It's worth noting that while the original project appears to have been abandoned, it has since been forked and is currently maintained here: https://github.com/openhtmltopdf/openhtmltopdf

Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?

#67
post #26

Please don't turn nice formats into a format that's similar to screenshots of text. Pandoc has an option to pack all images and styles needed to render the page into one html file: pandoc --self-contained input.html -o output.html

Please don't police what other people do.

Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?

#68
post #62

If generating PDF dynamically is what you really care about, consider Typst. https://typst.app/ We use it in production to generate reports, and it is amazing.

See https://lwn.net/Articles/1037577/ for a recent summary of what you can do with Typst.

Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?

#69
The last time I had to do this I scripted a back-end that scaled up headless chrome browsers to render web pages to PDF. I think it was using Puppeteer, but was a few years ago. (FWIW the decision I think was mostly driven by the environment, I think there are other options.)

Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?

#70
post #33
post #26

Please don't turn nice formats into a format that's similar to screenshots of text. Pandoc has an option to pack all images and styles needed to render the page into one html file: pandoc --self-contained input.html -o output.html

Being (not so easily) edited is often a feature, not a bug.

If that is your goal, you should be cryptographically signing your documents with your PGP key. That way you actually have assurance the document has not been modified rather than just hoping someone hasn't modified the document. Additionally, PGP can sign anything so you are open to use whatever format you want.
Post reply on HN