List of usage examples for org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination PDPageFitDestination PDPageFitDestination
public PDPageFitDestination()
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) {/* w w w . j ava2 s.co 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.pdfsam.pdfbox.component.PDFBoxOutlineUtilsTest.java
License:Open Source License
@Test public void toPageDestinationAction() { PDPageFitDestination destination = new PDPageFitDestination(); destination.setPageNumber(5);//from ww w .j ava 2 s.c o m PDActionGoTo action = new PDActionGoTo(); action.setDestination(destination); PDOutlineItem victim = new PDOutlineItem(); victim.setAction(action); assertEquals(5, PDFBoxOutlineUtils.toPageDestination(victim, null).get().getPageNumber()); }
From source file:org.pdfsam.pdfbox.component.PDFBoxOutlineUtilsTest.java
License:Open Source License
@Test public void toPageDestinationDestination() { PDPageFitDestination destination = new PDPageFitDestination(); destination.setPageNumber(5);//from w w w .j a v a2s .c o m PDOutlineItem victim = new PDOutlineItem(); victim.setDestination(destination); assertEquals(5, PDFBoxOutlineUtils.toPageDestination(victim, new PDDestinationNameTreeNode()).get() .getPageNumber()); }
From source file:org.pdfsam.pdfbox.component.PDFBoxOutlineUtilsTest.java
License:Open Source License
@Test public void toPageDestinationNamedDestination() throws IOException { PDPageFitDestination dest = new PDPageFitDestination(); dest.setPageNumber(5);//from ww w. j a va 2s . c om PDNamedDestination destination = new PDNamedDestination(); destination.setNamedDestination("ChuckNorris"); PDOutlineItem victim = new PDOutlineItem(); victim.setDestination(destination); PDDestinationNameTreeNode names = mock(PDDestinationNameTreeNode.class); when(names.getValue("ChuckNorris")).thenReturn(dest); assertEquals(5, PDFBoxOutlineUtils.toPageDestination(victim, names).get().getPageNumber()); }
From source file:uia.pdf.PDFMaker.java
License:Apache License
/** * Add bookmark./* w w w. j av a 2 s .co m*/ * @param page Page. * @param text bookmark text. * @throws IOException */ public PDPage addBookmark(ContentView view, PDPage page, String text) throws IOException { text = text == null ? "" : text.trim(); PDPageFitDestination dest = new PDPageFitDestination(); dest.setPage(page); for (PDOutlineItem oi : this.temp) { oi.setDestination(dest); } if (text.trim().length() > 0) { this.lastOI = new PDOutlineItem(); this.lastOI.setDestination(dest); this.lastOI.setTitle(text); this.hierarchyOI.peek().addLast(this.lastOI); this.bookmarkPages.add(new BookmarkPage(text, "" + this.doc.getNumberOfPages())); this.temp.add(this.lastOI); } page = view.drawBookmarks(page, this.temp); this.temp.clear(); return page; }