Live data from Hacker News

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

news.ycombinator.com

121–130 of 170 posts

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

#121
post #82
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

HTML+CSS+media files isn’t a nice format, and much less portable through time and space than PDF.

Not sure if I'm misreading your comment, but it's not plural files with all those formats separately

That's what the "self contained" option does: turn it into one nice file. Makes no difference if you copy example.pdf or example.html when both contain all images and styles (except one of them also contains the original semantic text)

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

#122
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.

If I were police, I could still not enforce that this is what they run until it's law. They're free to choose this option if they like the merits

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

#123
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.

May I recommend .html in that case? You can embed scripts that control who can run it, having it fetch a decryption token from a server or require a decryption password with a safe password hashing algorithm of your choice

It's much more versatile than PDF and, if the algorithm decides the user is allowed to read the document, then the user gets to make use of all of the document's options like a better search function (PDF can't find words that are bro-

ken across lines because that information of what's a word is gone, transformed into coordinates of what characters need to go where). It's also much more readable on different screen sizes, as the user can resize the window to whatever is comfortable on a 27" screen, or fits on their pocket e-reader. You can even draw it on a canvas if you want to prevent people from extracting the decrypted strings (though it's evil, you have that option). There's only benefits!

PDF is the lazy way to half-ass a read-only document while screwing, ahem, making anyone using a mobile phone zoom, pan, and squint. Thankfully, phones are falling out of fash— wait, scratch that, I just heard text reflow is more relevant than ever as phone use continues to soar

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

#124
post #109

Earlier quoted context omitted.

PDF is designed for annotations in the file format. You annotate in one editor, you can change the annotations in another. You can always distinguish between original content and annotations. I see no indication that Okular stores highlights or annotations in a separate file, that would be bizarre. There is no mechanism for annotations in HTML or the other formats I listed. An editor would just be editing the origina…

The W3C standardized HTML annotations years ago. There's a difference between a standard not existing versus people pretending it doesn't exist because it's not implemented by Chrome.

That's different. Those are a data structure defining annotations that are meant to be stored externally. They're not part of an HTML file like PDF annotations are. They're meant more for live collaborative commenting within a shared online space, not for making private portable annotations like PDF does.

And it's not a Chrome thing. I don't think any browsers support it, do they? It's not really clear there's a need for it, when collaborative editors already handle document annotations in their own ways.

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

#125

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 can use dvisvgm, pdftocairo, or Inkscape to convert PDF to SVG, which you can either use directly or insert inline into an HTML document.

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

#127
post #7

Just print to PDF in a browser, or automate that using a browser automation tool. For a non-browser-based open source solution, WeasyPrint. https://weasyprint.org/ For a proprietary solution, try Prince XML: https://www.princexml.com/

https://stirlingpdf.io also uses weasyprint !!

There was a critical book that I read two years ago that is only available online. The web presentation is full of images of maps, artifacts, etc to help contextualize the content. No PDF converter tool has ever been up to the job of just extracting the text until this one. Thank you!

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

#128
post #7

Just print to PDF in a browser, or automate that using a browser automation tool. For a non-browser-based open source solution, WeasyPrint. https://weasyprint.org/ For a proprietary solution, try Prince XML: https://www.princexml.com/

> Just print to PDF in a browser

I tried yesterday. With compliments to the moms of SWE who coded the functionality in firefox. Aparently puting the screen on a pdf page is an insurmontable task in 2025. (20 years ago was still doable). I had to make a screenshot and process the picture to print it.

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

#129
post #79
post #7

Just print to PDF in a browser, or automate that using a browser automation tool. For a non-browser-based open source solution, WeasyPrint. https://weasyprint.org/ For a proprietary solution, try Prince XML: https://www.princexml.com/

Most website do not have a print CSS, so it doesn’t print that nicely in PDF. But, I upvote weasyprint for that instead.

> Most website do not have a print CSS, so it doesn’t print that nicely in PDF.

Can't they just render the screen content in a pdf ? Seems easy for other programs to do this.

Post reply on HN