itext Text to PDF: iText 5 versus iText 7


The code to convert a plain text file to a PDF document is pretty simple whether you use iText 5 or iText 7. In iText 7, you have the advantage that you can define the alignment at the level of the document. In iText 5, you have to set the alignment for every separate Paragraph object.

To understand the real difference between iText 5 and iText 7 in this pair of examples, we have to take a look at the resulting PDF. In iText 5, we end up with 35 pages of text. In iText 7, we have the same text distributed over 38 pages.

The text is easier to read when created by iText 7 because different defaults are used when creating the layout. You could get the same result from iText 5 code, but then you'd have to change some values with respect to spacing.

In iText 7, the default values were chosen based on 16 years of experience with iText. This way, you get a better result with less code.

Want to know more?

Read Working with the RootElement which is chapter 5 in the iText 7: Building Blocks tutorial. Get the free ebook!