With version v2017R1, jPDFProcess API has a new function to set page labels in a PDF documents.
Look at the method called setPageLabels in the PDFDocument class.
setPageLabels(int[] indices, String prefix, String style, int offset) throws PDFException
Sets a page label to identify each page visually on the screen or in print. Consecutive pages create a labeling range using the same numbering system.
- Parameters:
- indices – The page indices with this page label.
- prefix – The label prefix for page labels in this range.
- style – The numbering style to be used for the numeric portion of each page label. Possible values are D, R, r, A, a.
- D: Decimal Arabic numerals
R: Uppercase Roman numerals
r: Lowercase Roman numerals
A: Uppercase letters
a: Lowercase letters - offset – The value of the numeric portion for the first page label in the range. Subsequent pages are numbered sequentially from this value, which must be greater than or equal to 1.
Here is a sample program that opens an existing PDF and sets page labels of the pages 1 to 3 in the PDF to use Roman numerals with a prefix.
// Load document PDFDocument pdfDoc = new PDFDocument("C:/test/in.pdf", null); int[] indices = { 0,1,2 }; String prefix = "Introduction "; // R style is for Upper Case Roman Numerals String style = "R"; int offset = 1; // Set the page labels pdfDoc.setPageLabels(indices, prefix, style, offset); // Save the output document pdfDoc.saveDocument("C:/test/out.pdf"); |