How to convert HTML code to PDF file in java?

Question:

I'm developing an application where I need to convert an HTML code, which is saved in the database, into a .PDF file. There is no need to save this file on the server.

I have never done anything like this. How to do this using Java?

Answer:

I do exactly that in an application developed with the Grails framework. I use a plugin called Rendering which, in turn, uses a Java library called Flying Saucer . I could post a Grails Example, but I don't think it would help you much since you're working with Java.

Flying Saucer uses a library called iText. This is the library that effectively turns an XHTML into a PDF. There are some licensing issues that need to be checked.

An answer on SOen where the same thing is recommended.

Scroll to Top
AllEscort