Live data from Hacker News

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

news.ycombinator.com

11–20 of 170 posts

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

#12
post #8

Earlier quoted context omitted.

doesn't pandoc rely on some engine itself?

Curious why that matters to you? I mean everything has dependencies (some of the solutions elsewhere require Chrome and other common solutions require the JVM). At least Pandoc is GPL.

It matters because pandoc is not rendering the website to pdf, it converts the html to latex and then uses a latex engine to render the pdf.

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

#14
post #5

Puppeteer 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/creating-pdfs-from-html-using-csharp

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

#16

https://gotenberg.dev/ ...has been working well for me for the last few years. It's a headless instance of Google Chrome with a golang wrapper. Runs well in Docker or a cloud instance.

gotenberg is really rock solid for us. Easy to deploy as a docker container to any infrastructure.

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

#18
post #13

chrome --headless --disable-gpu --print-to-pdf https://example.com

same: google-chrome --headless --disable-gpu --no-pdf-header-footer --hide-scrollbars --print-to-pdf-margins="0,0,0,0" --print-to-pdf --window-size=1280,720 https://example.com

ended up using headless chrome specifically to make sure javascript things rendered properly

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

#19
If you don't really need the PDF but just want to archive pages, SingleFile is better. It'll capture the entire page to a single HTML file and I find this is better than the PDF if I don't want to print it. It's a browser extension, but there's also a command line version (https://github.com/gildas-lormeau/single-file-cli) that uses Chrome or Chromium's headless mode.

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

#20
post #8

Earlier quoted context omitted.

doesn't pandoc rely on some engine itself?

Curious why that matters to you? I mean everything has dependencies (some of the solutions elsewhere require Chrome and other common solutions require the JVM). At least Pandoc is GPL.

There are multiple ways to "depend", so if pandoc executes some external tool all of the work then might as well use that external tool directly. You will get more control over how the conversion happens, know for what search for when in trouble etc.
Post reply on HN