Ask HN: What is nowadays (opensource) way of converting HTML to PDF?
81–90 of 170 posts
Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?
#82Please 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
Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?
#83Puppeteer and Playwright are the main open-source options nowadays, both solid for HTML → PDF once your print CSS is sorted. Don’t forget proper page breaks (break-before/after/inside) — e.g. break-after: page works in Chromium, while always doesn’t. For trickier pagination you can look at Paged.js, and I’d test layouts in Chrome/Edge before automating. Shameless plug: I run yakpdf.com, a hosted Puppeteer-based servi…
Seconded. I went with C# + Playwright. I tried iTextSharp, iText, PDFSharp, and wkhtmltopdf, but they all had limitations. I had good results with Playwright in minutes, outside of tweaking the CSS like you mention. I documented the process here[0] if anyone needs examples of the CSS and loading web fonts. Apologies for the article being long-winded – it was the first one I published. [0] https://johnh.co/blog/creati…
You can also easily generate screenshots if that's more suitable than PDFs.
You can also easily use this to do stuff like jam a set of images into a HTML table and PDF or screenshot them in that format.
Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?
#84Just 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/
I’ve had excellent experience with Prince XML and poor experience with everything else I’ve tried. Prince is fast, robust and reliable. Yes it costs money. So does developer time.
Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?
#85Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?
#86Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?
#87Earlier quoted context omitted.
I know, even though that depends on the editor. Okular for example places them in an extra file, last I checked. That's not unique to PDFs. HTML files are modifiable. There is nothing preventing an editor to put annotations in it as well.
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…
https://superuser.com/questions/333378/where-does-okular-sto...
Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?
#88Ghost script is working with postscript natively and will likely manage idiosyncrasies of web content better. It’s got a decent ecosystem, command line, you can find gui’s if that’s your thing (no judgement, your lifestyle is none of my business).
Many other good tools mentioned here as well, but if your asking because you need more, or fine grained (near infinite) control over the pdf composition, there’s nothing OSS I can think of that approaches its capabilities.
Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?
#89Re: Ask HN: What is nowadays (opensource) way of converting HTML to PDF?
#90It only handles like 5% of HTML, but it's the 5% I was using.
I've also had success producing PDFs with GhostScript from a PostScript file. PostScript is really easy to write, almost like SVG.