List of usage examples for org.apache.pdfbox.pdmodel PDDocumentNameDictionary getDests
public PDDestinationNameTreeNode getDests()
From source file:org.pdfmetamodifier.IOHelper.java
License:Apache License
/** * Save Outlines (bookmarks)./*from w ww . java 2 s .c o m*/ * * @param pdfFile * Source PDF file. * @param outlinesFile * File with Outlines (bookmarks) in user-frendly format. * @throws IOException */ /* * See: * https://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/PrintBookmarks.java?view=markup */ public static void saveOutlines(final File pdfFile, final File outlinesFile) throws IOException { PDDocument document = null; try { // Read PDF file. document = PDDocument.load(pdfFile); if (document.isEncrypted()) { throw new IOException("Document is encrypted."); } // Get data from PDF file. final PDDocumentCatalog catalog = document.getDocumentCatalog(); final PDDocumentOutline outlines = catalog.getDocumentOutline(); final PDPageTree pages = catalog.getPages(); final PDDocumentNameDictionary namesDictionary = new PDDocumentNameDictionary(catalog); final PDDestinationNameTreeNode destinations = namesDictionary.getDests(); // Convert. final List<String> lines = OutlineHelper.outlinesToLineList(outlines, pages, destinations); // Write line list into the text file. Files.write(outlinesFile.toPath(), lines); } finally { if (document != null) { document.close(); } } }
From source file:org.pdfsam.pdfbox.component.OutlineMerger.java
License:Open Source License
public OutlineMerger(PDDocument document) { requireNonNull(document, "Unable to retrieve bookmarks from a null document."); PDDocumentNameDictionary names = document.getDocumentCatalog().getNames(); if (names != null) { this.destinations = names.getDests(); }// w w w . j a va 2 s.c om this.outline = Optional.ofNullable(document.getDocumentCatalog().getDocumentOutline()); }
From source file:org.pdfsam.pdfbox.component.PDFBoxOutlineUtils.java
License:Open Source License
/** * @param document/* w w w.j a v a 2 s. c om*/ * @return the max bookmarks level where a page destination (page destination, named destination, goto action) is defined. */ public static int getMaxBookmarkLevel(PDDocument document) { PDDestinationNameTreeNode destinations = null; PDDocumentNameDictionary names = document.getDocumentCatalog().getNames(); if (names != null) { destinations = names.getDests(); } return getMaxBookmarkLevel(document.getDocumentCatalog().getDocumentOutline(), destinations, 0); }
From source file:org.pdfsam.pdfbox.PDFBoxOutlineLevelsHandler.java
License:Open Source License
public PDFBoxOutlineLevelsHandler(PDDocument document, String matchingTitleRegEx) { requireNonNull(document, "Unable to retrieve bookmarks from a null document."); this.document = document; this.pages = document.getPages(); PDDocumentNameDictionary names = document.getDocumentCatalog().getNames(); if (names != null) { this.namedDestinations = names.getDests(); }/*from ww w . j a v a2s. c o m*/ if (isNotBlank(matchingTitleRegEx)) { this.titleMatchingPattern = Pattern.compile(matchingTitleRegEx); } }