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

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

Introduction

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

Prototype

public PDPageXYZDestination() 

Source Link

Document

Default constructor.

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  ava 2s.  c o  m
 * @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:com.quanticate.opensource.pdftkbox.PDFBookmark.java

License:Apache License

public static PDOutlineItem createOutline(String title, int pageNumber, int yOffset, String zoom,
        ZoomType zoomType) {/* ww w.j a  v  a2s  .  c  o  m*/
    PDOutlineItem bookmark = new PDOutlineItem();
    bookmark.setTitle(title);

    PDPageDestination dest = null;
    if (zoom != null) {
        if (zoomType == ZoomType.Inherit || zoomType == ZoomType.ZoomPercent) {
            PDPageXYZDestination xyz = new PDPageXYZDestination();
            xyz.setTop(yOffset);
            dest = xyz;

            if (zoomType == ZoomType.Inherit) {
                xyz.setZoom(-1);
            } else {
                String zoomNoPcnt = zoom.substring(0, zoom.length() - 1).trim();
                float zoomf = Integer.parseInt(zoomNoPcnt) / 100.0f;
                xyz.setZoom(zoomf);
            }
        } else if (zoomType == ZoomType.FitPage) {
            dest = new PDPageFitDestination();
        } else if (zoomType == ZoomType.FitHeight) {
            dest = new PDPageFitHeightDestination();
        }
        // Otherwise fall through to the default, FitWidth
    }
    if (dest == null) {
        PDPageFitWidthDestination wdest = new PDPageFitWidthDestination();
        wdest.setTop(yOffset);
        dest = wdest;
    }

    dest.setPageNumber(pageNumber - 1);
    bookmark.setDestination(dest);
    return bookmark;
}

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;
}