I am trying to find a Java library that can convert from a HTML to a PDF using the CSS printing styles.

I need that this library be free for commercial use. Not like itext that you need to pay or use AGPL license showing all your code.


You have a few options:

  • openhtmltopdf - new code, still brewing, but has some great results
  • Apache FOP - can convert XML, not HTML, but might be usefull
  • itext the older version (version 2)
  • Wkhtmltopdf - not java, can call it from Java via external process, used it with great success so far
| improve this answer | |

Finally, the library choose was Flying Saucer that uses the capacities from an old open source version in itext and allow us to use not all CSS printing styles but at least the important ones.


Flying saucer accepts the CSS 2.1 Specification. You can get more info about it in link and check the CSS specification in internet (I have not privileges to put more than 2 links)

| improve this answer | |

You can use htmltopdf-java which is based on wkhtmltopdf.

| improve this answer | |

I know this is a bit old topic, but for future reference and future coders, I'm suggesting to use https://pdfmyurl.com which I personally use.

It does have a code example for .NET / C#, Java, JavaScript, PHP, Perl, Ruby, Python and VB.net.

Aside from the programmer-friendly platform, It does have a well-documented tutorial that can be easily followed.

| improve this answer | |

Not a Java library, but you can execute Chrome in headless mode (no GUI, just like Command Line), and order it to create a PDF or PNG file of the page (URL) you want.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.