List of usage examples for org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline PDOutlineItem findDestinationPage
public PDPage findDestinationPage(PDDocument doc) throws IOException
From source file:aplicacion.sistema.indexer.test.PDFTextStripperOrg.java
License:Apache License
private int getPageNumber(PDOutlineItem bookmark, List allPages) throws IOException { int pageNumber = -1; PDPage page = bookmark.findDestinationPage(document); if (page != null) { pageNumber = allPages.indexOf(page) + 1;//use one based indexing }//from w ww . j a v a 2 s .c o m return pageNumber; }
From source file:edu.isi.bmkeg.lapdf.extraction.LAPDFTextStripper.java
License:Apache License
private int getPageNumber(PDOutlineItem bookmark, List<COSObjectable> allPages) throws IOException { int pageNumber = -1; PDPage page = bookmark.findDestinationPage(document); if (page != null) { pageNumber = allPages.indexOf(page) + 1;//use one based indexing }//from w w w. j ava2s .c om return pageNumber; }
From source file:fr.aviz.hybridvis.utils.PDF.MultiScalePDFViewer.java
License:Open Source License
/** * @param PDDocument//from www . j a v a2 s. c o m * 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:ru.elibsystem.elis.utils.pdf.PdfToc.java
License:Apache License
/** * This will print the documents bookmarks to System.out. * * @param bookmark The bookmark to print out. * @param level A nesting level/*w ww . j av a 2s . co m*/ * * @throws IOException If there is an error getting the page count. */ protected void printBookmark(PDOutlineNode bookmark, Integer level) throws IOException { PDOutlineItem current = bookmark.getFirstChild(); while (current != null) { int pageIndex = 0; // first page int pageNumber = 1; // first page List<PDPage> pages = document.getDocumentCatalog().getAllPages(); for (PDPage page : pages) { if (page.equals(current.findDestinationPage(document))) { break; // pageNumbed finded } pageNumber++; pageIndex++; } String out = pageNumber + " " + level + " " + current.getTitle(); if (!isOutInFile()) { System.out.println(out); } else { getOutFileWriter().write(out + System.lineSeparator()); } printBookmark(current, level + 1); // reverse loop on ToC current = current.getNextSibling(); } }