/**
* If necessary, creates a new page label range entry in the PDF document.
* @param page The new area tree page being processed.
*/
private void checkPageLabels(final Page page) {
final PageCollection currentCollection = page.getParent();
final PositiveIntegerFormatter currentFormatter =
currentCollection.getPageNumberFormatter();
final PdfPageLabelStyle labelStyle = PDFRenderer
.convertPageLabelStyle(currentFormatter.getType());
/* Handle special case of the first page. */
if (this.currentAreaTreePage == null) {
this.pdfDoc.addPageLabelRange(0, labelStyle,
currentCollection.getPageNumberPrefix(), page.getNumber());
return;
}
/* In all other cases, we are looking for changes from the last page. */
final PageCollection previousCollection =
this.currentAreaTreePage.getParent();
if (currentCollection == previousCollection) {
/* The pages are in the same PageCollection. No new page label range
* entry is needed. */
return;
}
final PositiveIntegerFormatter previousFormatter =
previousCollection.getPageNumberFormatter();
if (currentFormatter.getType() == previousFormatter.getType()
&& currentCollection.getPageNumberPrefix()
.equals(previousCollection.getPageNumberPrefix())
&& page.getNumber() == this.pageCount) {
return;
}
this.pdfDoc.addPageLabelRange(this.pageCount - 1, labelStyle,
currentCollection.getPageNumberPrefix(), page.getNumber());