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

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

Introduction

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

Prototype

public PDPageLabels(PDDocument document) 

Source Link

Document

Creates an empty page label dictionary for the given document.

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);
            }/* www. j  a v a2s . c o m*/
        }

        doc.getDocumentCatalog().setPageLabels(pdPageLabels);

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

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