Example usage for org.apache.pdfbox.pdmodel.common PDPageLabels setLabelItem

List of usage examples for org.apache.pdfbox.pdmodel.common PDPageLabels setLabelItem

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.common PDPageLabels setLabelItem.

Prototype

public void setLabelItem(int startPage, PDPageLabelRange item) 

Source Link

Document

Sets the page label range beginning at the specified start page.

Usage

From source file:org.pdfgal.pdfgal.pdfgal.impl.PDFGalImpl.java

License:Open Source License

@Override
public void reIndexPageNumbers(final String inputUri, final String outputUri,
        final List<PDFGalPageNumbering> pdfGalPageNumberingList) throws IOException, COSVisitorException {

    if (StringUtils.isNotBlank(inputUri) && StringUtils.isNotBlank(outputUri)
            && CollectionUtils.isNotEmpty(pdfGalPageNumberingList)) {

        final PDDocument doc = PDDocument.load(inputUri);

        final PDPageLabels pdPageLabels = new PDPageLabels(doc);

        for (final PDFGalPageNumbering pageNumbering : pdfGalPageNumberingList) {
            if (pageNumbering.isInitializated()) {
                final PDPageLabelRange pdPageLabelRange = new PDPageLabelRange();
                pdPageLabelRange.setStyle(pageNumbering.getNumberingStyle().getValue());
                pdPageLabels.setLabelItem(pageNumbering.getPageNumber() - 1, pdPageLabelRange);
            }//  w  ww .  j  a v a  2 s.c  o m
        }

        doc.getDocumentCatalog().setPageLabels(pdPageLabels);

        doc.save(outputUri);
        doc.close();

    } else {
        throw new IllegalArgumentException(Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE);
    }
}