HTML to PDF with iText 2.1.7

Posted by in Software, Tutorial

Sometimes you need to use an older version of a product die to e.g. licensing changes. It’s my case with iText. While the new version looks fantastic, their changes (and removal of e.g. RTF output) are deal breakers for the feature set we need to maintain. Therefore, 2.1.7 is the most recent version we can use. Heh.

In maven, this would be:

The string resulted from the previous article can be printed out fairly easily.

First, we create a document and a writer:

We write the document:

And then we close the document and writer:

It’s easy and the result is here. You can see it’s very basic!

Note The API can throw a DocumentException which we need to catch.


A little experiment: If you find this post and ad below useful, please check the ad out :-)