Customizing the Page Number

By default, a PDF’s pages are numbered from 1 to the number of pages contained within it. PDFs often have the page number substituted — or labeled — with some alternative text. For example, the first few pages of a document could be labeled with Roman numerals instead of the usual Western Arabic numerals — e.g. instead of 1, 2, 3, 4, 5, the pages could be labeled I, II, III, IV, V and then continue on as 6, 7, 8, etc.

After producing a new document by shuffling around, adding, removing, or inserting new pages, it may be necessary to clear the page labels and possibly also set new ones.

This example demonstrates how to clear any existing page labels and add custom labels to the first three pages of a new document:

// Make a job with a source document as input.
var editorJob = new PSPDFKit.Document.Editor.Job(sourceDocument);

// Clear any existing page labels.
await editorJob.ClearPageLabelsAsync();

// Set custom labels for the first three pages.
var customLabels = new string[] { "Front Page", "Page B", "Contents Page" };
var numPages = await editorJob.GetPageCountAsync();
for (var i = 0; i < customLabels.Length && i < numPages; i++)
    await editorJob.SetPageLabelAsync(i, customLabels[i]);

// Generate a new document.
var newDocumentStorageFile = await PSPDFKit.Document.Editor.Editor.NewStorageFileFromJobAsync(editorJob);