Skip to main content
Skip table of contents

How can I read Roman page numbers?


Should I use labels or annotations to get Roman page numbers instead of indexed page numbers?


In Adobe Reader, the first pages of an ebook can have page numbers in the Roman number format. I would like to read these page numbers (instead of the indexed page number) with iText, but I don't know which properties (labels or annotations) I should use.

Posted on StackOverflow on Mar 20, 2015 by T N

You are looking for the PageLabelExample. In this example, we have a PDF, page_labels.pdf that has pages numbered like this:

Pages with page labels

Pages with page labels

In the listPageLabels() method, we create a txt file with list of page labels. To achieve this, use getPageLabels() method in the PdfDocument instance:

public void listPageLabels(String src, String dest) throws IOException {
    PrintStream out = new PrintStream(new FileOutputStream(dest));
    PdfReader reader = new PdfReader(src);
    PdfDocument pdfDoc = new PdfDocument(reader);

    String[] pageLabels = pdfDoc.getPageLabels();
    for (String textLabel : pageLabels) {
        out.println(textLabel);
    }
    out.flush();
    out.close();
    reader.close();
}

The result will be the following:

A
B
1
2
3
Movies-4
Movies-5
Movies-6
Movies-7
Movies-8

Click How can I read Roman page numbers? 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.