Live data from Hacker News

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

news.ycombinator.com

131–140 of 170 posts

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

#131
post #71

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.

PDF is literally digital paper. HTML has logical structure, it can adapt to different displays, etc. Sometimes you want one, sometimes, the other.

When do want the digital paper when you can have the more flexible one?

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

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

Rendering to SVG, at least that's what I did on https://fschutt.github.io/printpdf/

I am currently writing a WASM-ready PDF toolkit that can handle both HTML to PDF and then rendering PDF pages to SVG. However, it's not yet production-ready.

The underlying HTML engine is currently a severe "work in progress", but it gives me the low-level access that I need: https://azul.rs/reftest

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

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

Fyi... the preferred new syntax since 2022 is:

  --embed-resources --standalone.
https://github.com/rstudio/rmarkdown/issues/2382

https://pandoc.org/MANUAL.html#:~:text=Deprecated%20synonym%...

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

#136
I built this: https://github.com/dvcoolarun/web2pdf — a CLI tool for converting web pages to PDFs, recently open-sourced after adding several new features. (Might be useful!)

Not related to the thread, but if anyone is looking to hire a developer or knows of opportunities, I was recently let go and am actively searching. Any leads or feedback would be greatly appreciated.

Sample PDF: https://drive.google.com/file/d/1n7M1TKOptSsYiibrbvV_Yojx53T...

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

#137
Yeah, wkhtmltopdf can be a pain, especially with modern CSS/JS-heavy pages. One option you could try is PDFBolt - you can design a template in HTML/CSS once, then simply pass the JSON data and template ID. It handles dynamic content and modern layouts without all the quirks of wkhtmltopdf. You can also convert HTML content or URLs to PDFs.

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

#138
post #71

Earlier quoted context omitted.

PDF is literally digital paper. HTML has logical structure, it can adapt to different displays, etc. Sometimes you want one, sometimes, the other.

>Sometimes you want one, sometimes, the other. This is the part that the top commenter missed. Instead they decided that one format is "nice" and the other, by implication, isn't. I find PDFs a lot easier to keep organized en masse, I like that I can use them on any of my devices and it's easy for me to use them when I'm doing in-depth reading such as an ebook. Doubly so because my ereader also does text to speech an…

None of that sounds related to the format?

- A text to speech engine should work better with the original html structure where it sees bold tags, headings, and full sentences ra-

ther than broken-off ones

- Keeping PDFs organised, how would that differ from keeping any other filetype organised? I don't understand what difference you, "by implication", attribute to a file ending in .html or .pdf for being able to handle them en masse. If anything, searching across them will be vastly easier for software (self-written or third-party) and more reliable because it's all plain text

- Text and audio rendering syncing, I have no experience with but that doesn't sound like it ought to fundamentally work for a display format and not for the source text format. Of course, the software has to have support for this format (and otherwise it's trivial to pdfify a html but vice versa is nearly impossible)

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

#139
post #135
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

Fyi... the preferred new syntax since 2022 is: --embed-resources --standalone. https://github.com/rstudio/rmarkdown/issues/2382 https://pandoc.org/MANUAL.html#:~:text=Deprecated%20synonym%...

I noticed when trying it out for this comment, but then looked around when it was introduced and it seems recent (as in, an LTS distribution won't have it). Someone on stackoverflow said they get "unknown option --embed-resources". The old option will work for everyone and is also simpler, one instead of two parameters. People whose client supports the new option will see the upgrade suggestion when they run this. In the end I saw mainly downsides to mentioning the new rather than the old way

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

#140
post #131
post #71

Earlier quoted context omitted.

PDF is literally digital paper. HTML has logical structure, it can adapt to different displays, etc. Sometimes you want one, sometimes, the other.

When do want the digital paper when you can have the more flexible one?

Did you not read my reply to your root comment? I already answered this for you.

Each one has things the other can't do. Neither is universally more flexible.

Post reply on HN