Skip to content

Page Labels ​

Page labels provide display page numbers for PDF pages—for example, front matter labeled i, ii, and body pages starting at 1. Page labels differ from page indexes: indexes always start at 0, while labels are text shown to users for display and navigation.

Foxit PDF SDK for Web reads page labels through PDFDoc.getPageLabels(). You can read labels for specified page indexes or fetch all page labels at once.

Read Page Labels ​

PDFDoc.getPageLabels(pageIndexes) reads labels for the specified pages. If pageIndexes is omitted, all page labels are returned.

javascript
const pdfDoc = pdfViewer.getCurrentPDFDoc();

const allLabels = await pdfDoc.getPageLabels();
const labels = await pdfDoc.getPageLabels([0, 1, 2]);

The return value is an array of page label strings in the same order as the supplied page indexes.

Locate a Page by Label ​

To locate a page by label text, read all page labels first, then find the matching page index in application code.

javascript
const labels = await pdfDoc.getPageLabels();
const pageIndex = labels.findIndex(label => label === 'A-1');

if (pageIndex >= 0) {
    const docRender = pdfViewer.getPDFDocRender();
    await docRender.goToPage(pageIndex);
}

Relationship to Page Organization ​

After inserting, deleting, or moving pages, the SDK updates page label information according to the page organization operation. If your business UI shows outlines, thumbnails, or page number inputs, re-read page labels after page organization completes.

Notes ​

  • Page labels are for display and navigation; they are not the same as page indexes.
  • Page indexes start at 0; page labels may start at 1, i, A-1, or any other text.