Posts

Showing posts from 2013

Using Flying Saucer and iText in Java to convert XHTML to PDF

The situation Where I work, we were generating reports in XHTML, for printing. The styling should be easily configurable. The problem with this approach is the cross-browser look of your report. IE and Chrome print two completely different reports, so to speak. To prevent the difference between browsers, and to re-use the existing report generation, I decided I needed to render the print at the serverside. So I had html, and I wanted it to look the same on every computer. Pdf is a good medium for this purpose, so I needed a html to pdf library, for our Java system. I first tried iText by itself, but this did not apply the css. Browsing the web a bit further I found the combo Flying Saucer and iText , and this was a winning combination for us. Flying Saucer is a Java library that renders XHTML/XML + CSS to screen/image/PDF. For PDF there is a dependency on iText, a library to create pdf files. The code In this blogpost I provide some codesnippets, not a full working example.