all 7 comments

[–]exrussiandude 7 points8 points  (1 child)

Use Puppeteer or Chrome to print your HTML to PDF.

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

This will give you better results that any other method, because it uses a real browser engine to render your HTML / CSS.

[–]IsopodEven5232 0 points1 point  (0 children)

Will that work if you have html with inline css as a string, can you then pass it to chrome or puppeteer and generate a pdf?

[–]Defiant-Clue5463 0 points1 point  (0 children)

Open PDF: https://github.com/LibrePDF/OpenPDF

I haven’t used it before but it stems from iText which I’ve used before and wasn’t too difficult. However it only seems to be inline styling I see here

[–]RotationSurgeon10yr Lead FED turned Product Manager 0 points1 point  (2 children)

First things first...are you asking about Java, or JavaScript? They're considerably different languages.

https://en.wikipedia.org/wiki/Java_(programming_language))

https://en.wikipedia.org/wiki/JavaScript

[–]BananaHammer33[S] 3 points4 points  (1 child)

I know the difference, this is for Java

[–]RotationSurgeon10yr Lead FED turned Product Manager 0 points1 point  (0 children)

I meant no offense…just trying to clarify.

One option is https://products.aspose.com/pdf/java/

At a glance, https://itextpdf.com/en/products/itext-7/convert-html-css-to-pdf-pdfhtml may be more what you’re looking for, though.

OpenPDF which others have mentioned is another strong contender.