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

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

Introduction

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

Prototype

public void setZoom(float zoom) 

Source Link

Document

Set the zoom value for the page, values 0 or -1 imply that the current zoom will be used.

Usage

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) {/*from   w  w w.  j a  v  a 2  s. c om*/
    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;
}