Live data from Hacker News

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

news.ycombinator.com

51–60 of 170 posts

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

#51
post #48

Earlier quoted context omitted.

Or, please do? I use PDF's so I can send them to my iPad to read offline, highlight them, annotate them, and then send them back to my filesystem with highlights and annotations intact. I sure can't do that with any "nice formats" like HTML or TXT or EPUB or MOBI.

You could, though. What you are describing are features of an editor, not a file format. I can imagine a browser addon performing the same tasks.

PDF annotations sit within the file.

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

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

Prince XML looks nice but what about creating a PDF directly from a website? This often adds some problems, for example links still pointing to other pages on the web. But in my experience printing to PDF is often not good enough.

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

#53
post #24

A reverse of this question; what is the best way to convert pdf to html? We are required by accessibility law to make our PDFs WCAG compliant however it would be easier to convert these to HTML.

I have been using pdf2htmlex with some success. https://github.com/pdf2htmlEX/pdf2htmlEX

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

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

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?

#57
post #8

Earlier quoted context omitted.

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.

Forgive me but I don’t understand why that matters to you and am trying to understand what the issue with Latex is.

Because lots of things work this way. For example compilers built on LLV uses an intermediate language and Python uses byte code.

I suspect some html to pdf tools go through postScript.

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

#58
post #43

If your HTML is simply an intermediary to get you to a PDF, you could consider just skipping straight to building the PDF directly: https://pdfbox.apache.org This would be far more efficient than spinning up an entire browser and printing PDFs to disk.

Building PDF directly (unless you're creating documents, especially fillables) is non-intuitive. Most PDFs are people trying to capture live data in a cached manner. If not, using a preliminary format like Markdown/HTML/LaTeX/DocX/etc to generate your PDF is almost always more intuitive.

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

#59
post #20
post #8

Earlier quoted context omitted.

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.

My understanding and experience is that Latex has a significant learning curve and Pandoc provides a more gentle front end.

Of course Latex gives you fine control to hand tune the engine…but that doesn’t seem like what the OP is looking for.

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

#60
post #51
post #48

Earlier quoted context omitted.

You could, though. What you are describing are features of an editor, not a file format. I can imagine a browser addon performing the same tasks.

PDF annotations sit within the file.

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.
Post reply on HN