List of usage examples for com.lowagie.text.pdf PdfDestination addPage
public boolean addPage(PdfIndirectReference page)
From source file:docet.engine.PDFDocumentHandler.java
License:Apache License
private void writeTOCBookmarks(Collection<DocumentPart> documents, PdfWriter writer) { writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); PdfOutline root = writer.getRootOutline(); Map<DocumentPart, PdfOutline> outlines = new HashMap<>(); for (DocumentPart document : documents) { PdfOutline parent = outlines.getOrDefault(document.parent, root); PageBox page = document.pages.get(0); // PdfDestination dest = new PdfDestination(PdfDestination.XYZ, 0, 0, 0); PdfDestination dest = new PdfDestination(PdfDestination.FIT); LOGGER.log(Level.FINE, "Writing bookmark {0} - {1} to page {2}", new Object[] { title, document.name, document.startPageNo + page.getPageNo() }); dest.addPage(writer.getPageReference(document.startPageNo + page.getPageNo())); PdfOutline outline = new PdfOutline(parent, dest, document.name, true); outlines.put(document, outline); }//from w ww . j a v a2 s . c om }
From source file:org.xhtmlrenderer.pdf.ITextOutputDevice.java
License:Open Source License
private PdfDestination createDestination(RenderingContext c, Box box) { PdfDestination result = null; PageBox page = _root.getLayer().getPage(c, getPageRefY(box)); if (page != null) { int distanceFromTop = page.getMarginBorderPadding(c, CalculatedStyle.TOP); distanceFromTop += box.getAbsY() + box.getMargin(c).top() - page.getTop(); result = new PdfDestination(PdfDestination.XYZ, 0, page.getHeight(c) / _dotsPerPoint - distanceFromTop / _dotsPerPoint, 0); result.addPage(_writer.getPageReference(_startPageNo + page.getPageNo() + 1)); }/* w ww . j a va2 s . c om*/ return result; }
From source file:org.xhtmlrenderer.pdf.ITextOutputDevice.java
License:Open Source License
private void writeBookmark(RenderingContext c, Box root, PdfOutline parent, Bookmark bookmark) { String href = bookmark.getHRef(); PdfDestination target = null; if (href.length() > 0 && href.charAt(0) == '#') { Box box = _sharedContext.getBoxById(href.substring(1)); if (box != null) { PageBox page = root.getLayer().getPage(c, getPageRefY(box)); int distanceFromTop = page.getMarginBorderPadding(c, CalculatedStyle.TOP); distanceFromTop += box.getAbsY() - page.getTop(); target = new PdfDestination(PdfDestination.XYZ, 0, normalizeY(distanceFromTop / _dotsPerPoint), 0); target.addPage(_writer.getPageReference(_startPageNo + page.getPageNo() + 1)); }//from w ww. j av a2 s . co m } if (target == null) { target = _defaultDestination; } PdfOutline outline = new PdfOutline(parent, target, bookmark.getName()); writeBookmarks(c, root, outline, bookmark.getChildren()); }