List of usage examples for org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline PDOutlineItem getNextSibling
public PDOutlineItem getNextSibling()
From source file:com.github.joemcintyre.pdffinish.PDFFinish.java
License:Open Source License
/** * Show TOC entries at current hierarchy level, and sub-levels using recursive * call.//from w w w. j av a 2s.c o m * * @param entry Starting node. * @param indent Spaces to precede output text. */ private static void showEntry(PDOutlineNode entry, String spaces) { PDOutlineItem node = entry.getFirstChild(); while (node != null) { System.out.println(spaces + node.getTitle()); showEntry(node, spaces + " "); node = node.getNextSibling(); } }
From source file:com.quanticate.opensource.pdftkbox.Bookmarks.java
License:Apache License
protected void exportBookmark(PDOutlineNode outline, int level, PrintWriter output) throws IOException { PDOutlineItem current = outline.getFirstChild(); while (current != null) { // Handle this one PDFBookmark bookmark = new PDFBookmark(current, level); renderBookmark(bookmark, output); // Handle any children exportBookmark(current, level + 1, output); // Next one at our level, if any current = current.getNextSibling(); }/*from ww w .j av a 2 s. co m*/ }
From source file:com.vns.pdf.impl.PdfDocument.java
License:Apache License
public void fillBookmark(PDOutlineNode bookmark, String indentation) throws IOException { PDOutlineItem current = bookmark.getFirstChild(); while (current != null) { ActionData actionData = parsePDAction(current.getAction()); if (actionData == null) { actionData = parsePDDestination(current.getDestination()); }//from w ww.j a v a 2 s. co m Annotation annotation; if (actionData != null) { annotation = new Annotation(-1, -1, -1, -1, actionData.destX, actionData.destY, actionData.destPage, actionData.destZoom, indentation + current.getTitle()); } else { annotation = new Annotation(indentation + current.getTitle()); } this.doc.getBookmarks().add(annotation); fillBookmark(current, indentation + " "); current = current.getNextSibling(); } }
From source file:de.berber.kindle.annotator.lib.Bookmark.java
License:Apache License
@Override protected PDAnnotation toPDAnnotation(final @Nonnull PDDocumentOutline documentOutline, final @Nonnull PDPage page) { LOG.info("Creating bookmark"); final String OUTLINE_ENTRY_NAME = "Bookmarks"; // search for an outline entry called Bookmarks PDOutlineItem bookmarks = documentOutline.getFirstChild(); while (bookmarks != null) { if (OUTLINE_ENTRY_NAME.equals(bookmarks.getTitle())) { break; }/*ww w. j a v a 2s .c om*/ bookmarks = bookmarks.getNextSibling(); } // if we did not found an entry we have to add a new one if (bookmarks == null) { bookmarks = new PDOutlineItem(); bookmarks.setTitle(OUTLINE_ENTRY_NAME); documentOutline.appendChild(bookmarks); } // crate the bookmark entry final PDOutlineItem bookmark = new PDOutlineItem(); bookmark.setTitle("Bookmark on page " + getPage()); bookmark.setDestination(page); bookmarks.appendChild(bookmark); return null; }
From source file:de.offis.health.icardea.cied.pdf.extractor.PDFApachePDFBoxExtractor.java
License:Apache License
/** * This method will populate the text bookmark list. * /*from w w w. ja va2 s . c o m*/ * @param pdOutlineNode The node element for the bookmark item. * @param indentionString The base indention string to be used. */ @SuppressWarnings("unchecked") private void populateBookmarkTextList(PDOutlineNode pdOutlineNode, String indentionString) { PDOutlineItem currentOutlineItem = pdOutlineNode.getFirstChild(); while (currentOutlineItem != null) { bookmarkTextList.add(indentionString + currentOutlineItem.getTitle()); logger.trace(indentionString + currentOutlineItem.getTitle()); /* * Recursive call to fill List */ populateBookmarkTextList(currentOutlineItem, indentionString + bookmarkIndentionString()); /* * Get next outline item */ currentOutlineItem = currentOutlineItem.getNextSibling(); } // end while }
From source file:de.oio.jpdfunit.document.pdflibimpl.PdfBoxAnalyser.java
License:Open Source License
private void rekursionBookmarks(PDOutlineItem bla) { while (bla != null) { bookMarkList.add(bla.getTitle()); final PDOutlineItem child = bla.getFirstChild(); rekursionBookmarks(child);// w w w. ja v a 2 s .c o m bla = bla.getNextSibling(); } }
From source file:fr.aviz.hybridvis.utils.PDF.MultiScalePDFViewer.java
License:Open Source License
/** * @param PDDocument/*from w w w. ja v a2 s. c om*/ * Extracts the PDF's structure (up to 2 levels) if available * (PDF passed as PDDocument). Create an image of the structure * for each of the 1st level titles */ protected void pdfGetStructure_PDFbox(PDDocument document) throws IOException { PDDocumentOutline root = document.getDocumentCatalog().getDocumentOutline(); PDOutlineItem item; try { item = root.getFirstChild(); } catch (NullPointerException e) { System.out.println("No structure for pdf " + PDFname); return; } // fill map with titles per page while (item != null) { int pageNumber = findPageNumber(document, item.findDestinationPage(document)); String conc = item.getTitle(); if (conc.length() > 13) conc = conc.subSequence(0, 10) + "..."; System.out.println("Item:" + conc + " at page " + pageNumber); if (pageTitles.containsKey(item.findDestinationPage(document))) pageTitles.get(item.findDestinationPage(document)).add(conc); else { pageTitles.put(item.findDestinationPage(document), new ArrayList<String>()); pageTitles.get(item.findDestinationPage(document)).add(conc); } // do nothing with 2nd level children PDOutlineItem child = item.getFirstChild(); while (child != null) { System.out.println(" Child:" + child.getTitle()); child = child.getNextSibling(); } item = item.getNextSibling(); } int pn = 0; if (!hybrid) { BufferedImage itemImage; for (PDPage key : pages) { // for (PDPage key : pageTitles.keySet()) { ++pn; int titlesInPage = 0; List<String> titles = null; if (pageTitles.containsKey(key)) { titles = pageTitles.get(key); titlesInPage = titles.size(); } int w = (int) key.getArtBox().getWidth() - 200; int h = (int) key.getArtBox().getHeight() - 100; ; int x = (int) key.getArtBox().getLowerLeftX() + 50; int y = (int) key.getArtBox().getLowerLeftY() + 50; // calling createGraphics() to get the Graphics2D and setup for // drawing titles itemImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); if (titles_on && clouds_on) { itemImage = printTitlesAndCloudInImage(key, pn, titles, itemFont); } else if (titles_on) { if (titles != null) itemImage = printTitlesInImage(key, titles, itemFont); } else if (clouds_on) { itemImage = printCloudInImage(key, pn, titles, itemFont); } } } }
From source file:mj.ocraptor.extraction.tika.parser.pdf.PDF2XHTML.java
License:Apache License
void extractBookmarkText(PDOutlineNode bookmark) throws SAXException { PDOutlineItem current = bookmark.getFirstChild(); if (current != null) { handler.startElement("ul"); while (current != null) { handler.startElement("li"); handler.characters(current.getTitle()); handler.endElement("li"); // Recurse: extractBookmarkText(current); current = current.getNextSibling(); }// ww w. ja va 2 s .c o m handler.endElement("ul"); } }
From source file:net.padaf.preflight.helpers.BookmarkValidationHelper.java
License:Apache License
/** * This method explores the Outline Item Level and call a validation method on * each Outline Item. If an invalid outline item is found, the result list is * updated./* w ww . j a va 2 s .co m*/ * * @param inputItem * The first outline item of the level * @param handler * The document handler which provides useful data for the level * exploration (ex : access to the PDDocument) * @param result * @return true if all items are valid in this level. * @throws ValidationException */ protected boolean exploreOutlineLevel(PDOutlineItem inputItem, DocumentHandler handler, List<ValidationError> result) throws ValidationException { PDOutlineItem currentItem = inputItem; int oiValided = 0; while (currentItem != null) { if (!validateItem(currentItem, handler, result)) { return false; } oiValided++; currentItem = currentItem.getNextSibling(); } return true; }
From source file:org.apache.padaf.preflight.helpers.BookmarkValidationHelper.java
License:Apache License
/** * This method explores the Outline Item Level and call a validation method on * each Outline Item. If an invalid outline item is found, the result list is * updated./* ww w . j av a2s . com*/ * * @param inputItem * The first outline item of the level * @param handler * The document handler which provides useful data for the level * exploration (ex : access to the PDDocument) * @param result * @return true if all items are valid in this level. * @throws ValidationException */ protected boolean exploreOutlineLevel(PDOutlineItem inputItem, DocumentHandler handler, List<ValidationError> result) throws ValidationException { PDOutlineItem currentItem = inputItem; while (currentItem != null) { if (!validateItem(currentItem, handler, result)) { return false; } currentItem = currentItem.getNextSibling(); } return true; }