Example usage for org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination PDPageXYZDestination setPage

List of usage examples for org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination PDPageXYZDestination setPage

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination PDPageXYZDestination setPage.

Prototype

public void setPage(PDPage page) 

Source Link

Document

Set the page for a local destination.

Usage

From source file:com.github.joemcintyre.pdffinish.PDFFinish.java

License:Open Source License

/**
 * Update table of contents in destination document.
 * /*from ww  w . j ava2  s  .com*/
 * @param document PDF document to update.
 */
private void updateTOC(PDDocument document) {
    PDDocumentOutline outline = new PDDocumentOutline();
    document.getDocumentCatalog().setDocumentOutline(outline);
    PDOutlineItem topItem = new PDOutlineItem();
    topItem.setTitle(title);
    outline.appendChild(topItem);

    try {
        PDFTextFinder finder = new PDFTextFinder(fontList);
        List<PDFTextFinder.PDFText> headings = finder.getTextList(document);
        PDOutlineItem level[] = { topItem, null, null, null };
        for (PDFTextFinder.PDFText heading : headings) {
            PDPageXYZDestination dest = new PDPageXYZDestination();
            dest.setPage(heading.page);

            PDOutlineItem bookmark = new PDOutlineItem();
            bookmark.setDestination(dest);
            bookmark.setTitle(heading.text);
            level[heading.tag - 1].appendChild(bookmark);
            level[heading.tag] = bookmark;
        }
    } catch (IOException e) {
        System.out.println("Error :" + e);
    }

    topItem.openNode();
    outline.openNode();
}

From source file:org.pdfmetamodifier.OutlineHelper.java

License:Apache License

private static PDOutlineItem createOutlineItem(final String title, final int pageNumber,
        final PDPageTree pages) {
    final PDOutlineItem outlineItem = createOutlineItem(title);

    final PDPageXYZDestination destination = new PDPageXYZDestination();
    destination.setPage(pages.get(pageNumber - 1));

    outlineItem.setDestination(destination);

    return outlineItem;
}