Live data from Hacker News

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

news.ycombinator.com

161–170 of 170 posts

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

#162
post #144

Earlier quoted context omitted.

So is there a need for it or isn't there? > That's different. Those are a data structure defining annotations that are meant to be stored externally. The protocol is a separate standard. The format is JSON-LD. Putting JSON-LD into HTML isn't a question mark. (There's info at W3C.org about how to do that, too. Not that it's necessary. You can guess what it says.)

Sorry, yes you're right the annotations can be embedded too. But these aren't meant for direct user annotations in a general way. The web standard doesn't define any standardized mechanism for one user to add highlights and comments, and another user to see them and edit them further. The annotations are tools that software can use for its own purposes. They're not a user-facing feature like they are in PDF. They're…

I don't know what "these aren't meant for direct user annotations in a general way" is supposed to mean.

> [It] doesn't define any standardized mechanism for one user to add highlights and comments, and another user to see them and edit them further.

It does.

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

#163
post #157

Earlier quoted context omitted.

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.

Sure, I don't mean that anyone would look at the Latex in between. I'm just saying that if tool x directly calls tool y to do the job then might as well use tool y directly.

Since hammers and nails are a common tool-workpiece example…consider the nail gun.

Theoretically you can drive nails with a 22 caliber blank cartridge without making the “call” through a nail gun. But you won’t finish laying shingles as quickly and easily…

Or to put it another way, there’s a reason assemblers are almost always better than machine code and compilers are almost always better than assemblers for the ends people care about.

I mean why use Latex at all when you could write your own typesetting language? Maybe because you are not a knuth.

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

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

I was excited to try this today, but this is unusable. It absolutely mangles the page.

  - It duplicated the headline, one in the correct place top-center but then a 2nd copy of the headline left-aligned below that.
  - It shrunk the width of the content of the page (in fact, it seems to have completely discarded the css for the #content selector)
  - It discarded the CSS for my code blocks, so now they are unreadable.
  - My images are no longer center-aligned
  - It added CSS that was not in the original document. For some reason, it addded hyphens: auto, overflow-wrap: break-word, text-rendering: optimizeLegibility, font-kerning: normal . None of those rules existed in the original document anywhere. Now my text is breaking mid-word with hyphens inserted.
  - It pointlessly HTML-escaped some characters (like every quotation mark in every paragraph). This didn't break anything, but just... why?
Implementing the same functionality is like less than 100 lines of python, so I'm just going to go that route. I've implemented it once before, but it was for a previous company so I no longer have access to that code, but its like 1 afternoon of scripting and doesn't randomly destroy your documents. I don't know how pandoc got this so wrong.

For context: the document I am attempting to process has no javascript. It is a simple Emacs Org document (similar to markdown) rendered to HTML and then processed with pandoc. The only external content was a couple of images.

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

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

I was excited to try this today, but this is unusable. It absolutely mangles the page. - It duplicated the headline, one in the correct place top-center but then a 2nd copy of the headline left-aligned below that. - It shrunk the width of the content of the page (in fact, it seems to have completely discarded the css for the #content selector) - It discarded the CSS for my code blocks, so now they are unreadable. - M…

Huh, that's a bummer! I only used it once myself to send colleagues draft versions of some markdown file that would later go on our blog, maybe it somehow helped that the source was markdown instead of html? Not sure, I'm sorry to hear of this disappointing experience :/

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

#166
post #165

Earlier quoted context omitted.

I was excited to try this today, but this is unusable. It absolutely mangles the page. - It duplicated the headline, one in the correct place top-center but then a 2nd copy of the headline left-aligned below that. - It shrunk the width of the content of the page (in fact, it seems to have completely discarded the css for the #content selector) - It discarded the CSS for my code blocks, so now they are unreadable. - M…

Huh, that's a bummer! I only used it once myself to send colleagues draft versions of some markdown file that would later go on our blog, maybe it somehow helped that the source was markdown instead of html? Not sure, I'm sorry to hear of this disappointing experience :/

> maybe it somehow helped that the source was markdown instead of html?

That's probably it. Most of my issues were related to CSS, which markdown does not have[0]. The duplicated headline wasn't CSS though, that is by far the oddest issue. I'll probably file a bug report to pandoc after I replace all the text in this document with lorem ipsum (it is a document for work, so I can't share it publicly in its current form).

[0] unless you embedded your own CSS since markdown technically allows arbitrary HTML

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

#168
post #128
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/

> Just print to PDF in a browser I tried yesterday. With compliments to the moms of SWE who coded the functionality in firefox. Aparently puting the screen on a pdf page is an insurmontable task in 2025. (20 years ago was still doable). I had to make a screenshot and process the picture to print it.

Orion browser produces PDFs which are exactly what you see on screen.

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

#169

Earlier quoted context omitted.

HTML could do everything PDF does in theory but it doesn’t in practice because the tooling doesn’t exist.

My exercise bike can play Doom on its display in theory. Theory doesn't matter here, tooling and standards do. And PDF doesn't just have the tooling for highlighting and annotations, it has the standards for them so that tools support them in an interoperable way. A highlight made with one tool can be removed with another, without altering the underlying content.

It’s a credible argument, but to be clear one I didn’t comment on. It’s the logical next question if I’m correct, which I am.

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

#170
post #157

Earlier quoted context omitted.

Sure, I don't mean that anyone would look at the Latex in between. I'm just saying that if tool x directly calls tool y to do the job then might as well use tool y directly.

Since hammers and nails are a common tool-workpiece example…consider the nail gun. Theoretically you can drive nails with a 22 caliber blank cartridge without making the “call” through a nail gun. But you won’t finish laying shingles as quickly and easily… Or to put it another way, there’s a reason assemblers are almost always better than machine code and compilers are almost always better than assemblers for the end…

You're confusing wrappers with alternatives. The comparison is more like if somebody published a script called html-to-pdf.sh which directly calls, e.g, chrome, would you want to use this script or use chrome directly? I would prefer the latter because (1) I would know what actually does the conversion, (2) I would know what to search for on the web should I need to tweak the output. This knowledge gives me more power as I know the actual converter. The wrapper script perhaps only helps with what the command line should be.
Post reply on HN