itext Columns: iText 5 versus iText 7

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Remarks

In iText 5, you can't use the add() method to add a Paragraph to a Document if you want to organize the content in columns. We can't reuse the code of the Text2Pdf.java (iText 5) example.

Instead we have to create a ColumnText object, we have to add all the Paragraph objects to this object, and once we've finished adding all the content, we can start rendering that content using the go() method. While doing so, we have to keep track of the columns, and create new pages when necessary.

What we fixed in iText 7:

With iText 7, we can copy and paste the code from the Text2Pdf.java (iText 7) example. We can continue using the add() method the same way we did before. If we want to render the content in two columns instead of in one, we simple have to change the document renderer:

Rectangle[] columns = {
    new Rectangle(36, 36, 254, 770),
    new Rectangle(305, 36, 254, 770)};
document.setRenderer(new ColumnDocumentRenderer(document, columns));

Want to know more?

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



Got any itext Question?