Skip to main content
Skip table of contents

How to continue an ordered list on a second page?

I am currently creating the document by creating ColumnText objects that are placed at specific coordinates. The content consists of variable data (text/barcodes/images) that is added to existing PDF documents/templates (think boiler plate). Most commonly, I have to place various sections of text in specific places.

I know how to create an ordered list, but I have come across a situation where the list begins with #1 on the first page and then #2-4 on the top of the second page. I use two different templates for p1 and p2.

However, when I start a new list for the part on the second page, iText starts numbering that new list from 1 instead of continuing with 2.

Posted on StackOverflow on Mar 26, 2015 by rcurrydev

You don't need two List objects, one for the first page and one for the second page. iText 7 provides a ColumnDocumentRenderer class and you can easily set the areas where you want your elements to appear.

Document doc = new Document(pdfDoc);
        doc.setRenderer(new ColumnDocumentRenderer(doc, new Rectangle[]{new Rectangle(250, 400, 250, 406)}));

In the renderer constructor the second parameter is an array of columns (one column in this code snippet).

Now if you add to the document any sort of data, be sure it will appear only in the areas, you've specified. The list order won't be lost as well.

List list = new List(ListNumberingType.DECIMAL);
        for (int i = 0; i < 10; i++) {
            list.add("This is a list item. It will be repeated a number of times. "
                    + "This is done only for test purposes. "
                    + "I want a list item that is distributed over several lines.");
        }
        doc.add(list);

Take a look at the ListInColumn example for more information. Here is what the result looks like:

Screenshot

Screenshot

Click this link if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.