What is the difference between getPageLabels and getPageLabelFormats?

Tags: page labelsiText 7

I have a program that calls PdfPageLabels.getPageLabels() and PdfPageLabels.getPageLabelFormats() on the same PdfReader object on successive lines of my code:

PdfPageLabels.PdfPageLabelFormat[] pplf = 
String[] labs = PdfPageLabels.getPageLabels(reader);
I would have expected the two calls always to return arrays of the same length, they are supposed to be the same labels. This is true most of the time, but occasionally this is NOT the case.

I have an example. It's a 150Mb PDF file which appears to have 4670 labels via getPageLabels(), but only 1 via getPageLabelFormats(). So my question is: Under what circumstances could the two calls return arrays of different lengths?

Posted on StackOverflow on Dec 3, 2015 by paulb

There is no getPageLabelFormats() method in iText 7. To learn the answer for your question, please, follow this link.

If you want to get the page labels, you should now use this code:

PdfReader reader = new PdfReader(src);
PdfDocument pdfDoc = new PdfDocument(reader);
String[] pageLabels = pdfDoc.getPageLabels();

The PageLabelNumberingStyleConstants enumeration in iText 7 can be used when creating page labels like this:

pdfDoc.getPage(4).setPageLabel(PageLabelNumberingStyleConstants.DECIMAL_ARABIC_NUMERALS, "Custom-", 2);

Inspect the createPdf() method in PageLabels example to learn more.