Bookmark(Bookmark parent, PdfDestination destination, String title) { this.pdfOutline = new PdfOutline(parent.pdfOutline, destination, title, false); this.level = parent.level + 1; }
/** * Adds a named outline to the document . * @param outline the outline to be added * @param name the name of this local destination */ void addOutline(PdfOutline outline, String name) { localDestination(name, outline.getPdfDestination()); }
/** Helper for the constructors. * @param parent the parent outline * @param title the title for this outline * @param open <CODE>true</CODE> if the children are visible */ void initOutline(PdfOutline parent, String title, boolean open) { this.open = open; this.parent = parent; writer = parent.writer; put(PdfName.TITLE, new PdfString(title, PdfObject.TEXT_UNICODE)); parent.addKid(this); if (destination != null && !destination.hasPage()) // bugfix Finn Bock setDestinationPage(writer.getCurrentPage()); }
/** * Recursive method to update the count in the outlines. */ void traverseOutlineCount(PdfOutline outline) { java.util.List<PdfOutline> kids = outline.getKids(); PdfOutline parent = outline.parent(); if (kids.isEmpty()) { if (parent != null) { parent.setCount(parent.getCount() + 1); } } else { for (int k = 0; k < kids.size(); ++k) { traverseOutlineCount(kids.get(k)); } if (parent != null) { if (outline.isOpen()) { parent.setCount(outline.getCount() + parent.getCount() + 1); } else { parent.setCount(parent.getCount() + 1); outline.setCount(-outline.getCount()); } } } }
/** * Recursive method used to write outlines. */ void outlineTree(PdfOutline outline) throws IOException { outline.setIndirectReference(writer.getPdfIndirectReference()); if (outline.parent() != null) outline.put(PdfName.PARENT, outline.parent().indirectReference()); java.util.List<PdfOutline> kids = outline.getKids(); int size = kids.size(); for (int k = 0; k < size; ++k) outlineTree(kids.get(k)); for (int k = 0; k < size; ++k) { if (k > 0) kids.get(k).put(PdfName.PREV, kids.get(k - 1).indirectReference()); if (k < size - 1) kids.get(k).put(PdfName.NEXT, kids.get(k + 1).indirectReference()); } if (size > 0) { outline.put(PdfName.FIRST, kids.get(0).indirectReference()); outline.put(PdfName.LAST, kids.get(size - 1).indirectReference()); } for (int k = 0; k < size; ++k) { PdfOutline kid = kids.get(k); writer.addToBody(kid, kid.indirectReference()); } }
/** * Writes the outline tree to the body of the PDF document. */ void writeOutlines() throws IOException { if (rootOutline.getKids().size() == 0) return; outlineTree(rootOutline); writer.addToBody(rootOutline, rootOutline.indirectReference()); }
fith = pageSize.getHeight() - fith; PdfDestination destination = new PdfDestination(PdfDestination.FITH, fith); while (currentOutline.level() >= section.getDepth()) { currentOutline = currentOutline.parent(); PdfOutline outline = new PdfOutline(currentOutline, destination, section.getBookmarkTitle(), section.isBookmarkOpen()); currentOutline = outline;
/** * Constructs a <CODE>PdfOutline</CODE>. * <P> * This is the constructor for an <CODE>outline entry</CODE>. * * @param parent the parent of this outline item * @param action the <CODE>PdfAction</CODE> for this outline item * @param title the title of this outline item * @param open <CODE>true</CODE> if the children are visible */ public PdfOutline(PdfOutline parent, PdfAction action, String title, boolean open) { super(); this.action = action; initOutline(parent, title, open); }
put(PdfName.C, new PdfArray(new float[]{color.getRed()/255f,color.getGreen()/255f,color.getBlue()/255f})); flag |= 1; if (flag != 0) put(PdfName.F, new PdfNumber(flag)); if (parent != null) { put(PdfName.PARENT, parent.indirectReference()); put(PdfName.DEST, destination); put(PdfName.A, action); if (count != 0) { put(PdfName.COUNT, new PdfNumber(count));
/** * Gets the title of this outline * @return the title as a String */ public String getTitle() { PdfString title = (PdfString)get(PdfName.TITLE); return title.toString(); }
/** * Updates the count in the outlines. */ void calculateOutlineCount() { if (rootOutline.getKids().size() == 0) return; traverseOutlineCount(rootOutline); }
/** * Recursive method to update the count in the outlines. */ void traverseOutlineCount(PdfOutline outline) { ArrayList kids = outline.getKids(); PdfOutline parent = outline.parent(); if (kids.isEmpty()) { if (parent != null) { parent.setCount(parent.getCount() + 1); } } else { for (int k = 0; k < kids.size(); ++k) { traverseOutlineCount((PdfOutline)kids.get(k)); } if (parent != null) { if (outline.isOpen()) { parent.setCount(outline.getCount() + parent.getCount() + 1); } else { parent.setCount(parent.getCount() + 1); outline.setCount(-outline.getCount()); } } } }
/** * Recursive method used to write outlines. */ void outlineTree(PdfOutline outline) throws IOException { outline.setIndirectReference(writer.getPdfIndirectReference()); if (outline.parent() != null) outline.put(PdfName.PARENT, outline.parent().indirectReference()); ArrayList kids = outline.getKids(); int size = kids.size(); for (int k = 0; k < size; ++k) outlineTree((PdfOutline)kids.get(k)); for (int k = 0; k < size; ++k) { if (k > 0) ((PdfOutline)kids.get(k)).put(PdfName.PREV, ((PdfOutline)kids.get(k - 1)).indirectReference()); if (k < size - 1) ((PdfOutline)kids.get(k)).put(PdfName.NEXT, ((PdfOutline)kids.get(k + 1)).indirectReference()); } if (size > 0) { outline.put(PdfName.FIRST, ((PdfOutline)kids.get(0)).indirectReference()); outline.put(PdfName.LAST, ((PdfOutline)kids.get(size - 1)).indirectReference()); } for (int k = 0; k < size; ++k) { PdfOutline kid = (PdfOutline)kids.get(k); writer.addToBody(kid, kid.indirectReference()); } }
fith = pageSize.getHeight() - fith; PdfDestination destination = new PdfDestination(PdfDestination.FITH, fith); while (currentOutline.level() >= section.getDepth()) { currentOutline = currentOutline.parent(); PdfOutline outline = new PdfOutline(currentOutline, destination, section.getBookmarkTitle(), section.isBookmarkOpen()); currentOutline = outline;
/** * Writes the outline tree to the body of the PDF document. */ void writeOutlines() throws IOException { if (rootOutline.getKids().size() == 0) return; outlineTree(rootOutline); writer.addToBody(rootOutline, rootOutline.indirectReference()); }
/** * Constructs a <CODE>PdfOutline</CODE>. * <P> * This is the constructor for an <CODE>outline entry</CODE>. * * @param parent the parent of this outline item * @param destination the destination for this outline item * @param title the title of this outline item * @param open <CODE>true</CODE> if the children are visible */ public PdfOutline(PdfOutline parent, PdfDestination destination, String title, boolean open) { super(); this.destination = destination; initOutline(parent, title, open); }
put(PdfName.C, new PdfArray(new float[]{color.getRed()/255f,color.getGreen()/255f,color.getBlue()/255f})); flag |= 1; if (flag != 0) put(PdfName.F, new PdfNumber(flag)); if (parent != null) { put(PdfName.PARENT, parent.indirectReference()); put(PdfName.DEST, destination); put(PdfName.A, action); if (count != 0) { put(PdfName.COUNT, new PdfNumber(count));
/** * Gets the title of this outline * @return the title as a String */ public String getTitle() { PdfString title = (PdfString)get(PdfName.TITLE); return title.toString(); }
/** * Updates the count in the outlines. */ void calculateOutlineCount() { if (rootOutline.getKids().size() == 0) return; traverseOutlineCount(rootOutline); }
/** * Opens the document. * <P> * You have to open the document before you can begin to add content * to the body of the document. */ public void open() { if (!open) { super.open(); writer.open(); rootOutline = new PdfOutline(writer); currentOutline = rootOutline; } try { initPage(); } catch(DocumentException de) { throw new ExceptionConverter(de); } }