What is the difference between getPageLabels and getPageLabelFormats?

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

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 =
    PdfPageLabels.getPageLabelFormats(reader);
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.



Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now