Live data from Hacker News

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

news.ycombinator.com

31–40 of 170 posts

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

#31
post #10

if you are doing html to pdf, you might also need the ability to merge. a few more features and you're better of with a commercial solution.

Merge what?

I assume combining 2+ documents. For example, attaching a cover page with document owner/version control/lifecycle information to an existing PDF.

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

#32
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

Pandoc would be my preferred tool. It is excellent at converting between other formats as well.

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

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

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

#35
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/

+1 to weasyprint; I have used weasyprint with a django production system for a few years now, and it works well enough that I never have to think about it. I'm not doing anything fancy, though, but for me it has worked well.

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

#36
post #11

Don’t. Show a web page and open the print dialog, and tell people to save as PDF. All major browsers support this, and the browser HTML to PDF code is the most robust and accurate.

That does make sense where possible. I do feel like OPs question is super relevant if you are doing anything where the PDF has to be rendered server side, like say as part of a larger data process when producing an exportable report in PDF format.

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

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

I was thinking this too, PDF's exist so people don't mess with the document. That said, it's still a clever feature, and pandoc can convert html into a pdf as well with a conversion engine. That said, I suspect it'll fail on anything sufficiently complex

pandoc input.html -o output.pdf --pdf-engine=

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

#38

[dead]

wkhtmltopdf is pretty out of date at this point and headless Chrome/Chromium or something that wraps them is probably a better and safer, roughly equivalent, alternative. Docker might not be a great option if you're already running a containerized service and don't want to deal with getting them to play nice together.

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

#39
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/

WeasyPrint works really well for me. It can support all of the languages and fonts I need. I run it on AWS Lambda and in Docker as a web service.

I previously used WKHTMLTOPDF, but it hasn't been supported for years and doesn't support the latest CSS, etc. It does support JS if you need it, but I'd probably look at headless Chromium or another solution for JS if needed.

Edit: Previous post with some good discussion: https://news.ycombinator.com/item?id=26578826

Post reply on HN