Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fop-core/src/main/java/org/apache/fop/pdf/PDFPageLabels.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ public void addPageLabel(int index, String pageLabel) {
currentPageLabelType = DECIMAL;
currentPageNumber = Integer.parseInt(pageLabel);
int zeroPadding = 0;
if (pageLabel.charAt(zeroPadding) == '0') {
if (currentPageNumber == 0) {
// a page numbered 0: /St must be at least 1, so a label of zeros is written as a
// prefix; counting its leading zeros below would run past its end
currentPageLabelType = PREFIX;
addNewPageLabel = true;
} else if (pageLabel.charAt(zeroPadding) == '0') {
do {
zeroPadding++;
} while (pageLabel.charAt(zeroPadding) == '0');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,20 @@ public void testAddPageLabel() throws IOException {
baos.close();
}

/**
* A page labelled "0" is labelled as a prefix, since /St must be at least 1; counting the leading
* zeros of "0" ran past its end.
*/
@Test
public void testPageNumberedZero() throws IOException {
PDFDocument pdfDoc = mock(PDFDocument.class);
PDFPageLabels pageLabels = new PDFPageLabels();
pageLabels.setDocument(pdfDoc);
pageLabels.addPageLabel(0, "0");
pageLabels.addPageLabel(1, "1");
pageLabels.addPageLabel(2, "2");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pageLabels.getNums().output(baos);
assertEquals("[0 << /P (0) >> 1 << /S /D >>]", baos.toString());
}
}