Live data from Hacker News

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

news.ycombinator.com

111–120 of 170 posts

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

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

Seconded. In my eccentric workflow, I use Weasyprint to convert HTML emails to more portable PDFs. A surprisingly successful experiment.

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

#113

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.

Seconding.. gotenberg has been solid for us. We also make use of it's convert from Word to PDF feature and it's been really solid.

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

#114
post #110

I wrote a solution in 2010 that used headless Firefox with some plugins to generate a PDF and then had the graphic designer write print CSSes. It was driven by Perl and was a convenient way for non-programmers to design forms. Unfortunately, that server and software stack is still around and still in production.

> Unfortunately, that server and software stack is still around and still in production. that means you did a good job.

2010-era Firefox is probably plagued by security holes.

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

#115
post #114
post #110

Earlier quoted context omitted.

> Unfortunately, that server and software stack is still around and still in production. that means you did a good job.

2010-era Firefox is probably plagued by security holes.

If your print-file generation code tries to exploit the headless browser you use to turn its outputs into PDF something has gone very wrong already.

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

#117
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…

You made me realize that tractor feed roll paper would be really great for printed web pages, no page breaks! Kinda like reading scrolls of yore.

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

#118
Clearly,a million people have tried to find an answer for this question. I've tried. At least one of my attempts was an XY problem. I was converting generated HTML that would never see a browser. It was never intended to see a browser. The people generating it were very good at HTML/CSS/JS, but didn't know how to produce the same content outside HTML.

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

#119
post #76

jsPDF is a work of art https://parall.ax/products/jspdf

Been looking at this one. I inherited a project and I set it up to use puppeteer and chrome server side to generate a PDF from HTML but it's too much overhead. I want to do this all on the frontend because it should be simple enough to do and can use less resources on the server.

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

#120
post #108
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 turn nice formats into a format that's similar to screenshots of text Converting HTML to PDF shouldn't result in an image wrapped in a PDF. Text will be preserved as text in the final PDF. (Unless the converter is garbage, of course.)

If you've ever copied text out of a PDF, you'll know it's not the original text anymore. Besides ligatures, you get broken sentences with extra hyphens inserted in wrong places (that were word/line breaks in the PDF-rendered version), if it'll properly let you select more than a few words at all. It works like "put these couple words at position x,y" and not (html's) semantic "here comes a heading" tag that helps people accessibly read your text, and if you're not suffering from any impairment or mobile devices with narrower screens than this particular render was designed for, it also lets you work with the document more easily. It's like you remove all HTML and keep only the CSS: all definitions of what's a section, sentence, emphasis, or caption are gone

I didn't mean literally an image, hence saying image-like. You get similar limitations to when using OCR, which seems very image-like to me

Post reply on HN