Example usage for org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline PDOutlineNode getFirstChild

List of usage examples for org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline PDOutlineNode getFirstChild

Introduction

In this page you can find the example usage for org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline PDOutlineNode getFirstChild.

Prototype

public PDOutlineItem getFirstChild() 

Source Link

Usage

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  a v  a2s  .com*/
 * 
 * @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 www.ja  v a  2  s . c  o  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 w  w  .jav a  2 s . com
        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.offis.health.icardea.cied.pdf.extractor.PDFApachePDFBoxExtractor.java

License:Apache License

/**
 * This method will populate the text bookmark list.
 * /*from www  .j a  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: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();
        }//from  w ww .  ja  v a  2 s  .  c  om
        handler.endElement("ul");
    }
}

From source file:org.apache.tika.parser.pdf.AbstractPDF2XHTML.java

License:Apache License

void extractBookmarkText(PDOutlineNode bookmark) throws SAXException, IOException, TikaException {
    PDOutlineItem current = bookmark.getFirstChild();

    if (current != null) {
        xhtml.startElement("ul");
        while (current != null) {
            xhtml.startElement("li");
            xhtml.characters(current.getTitle());
            xhtml.endElement("li");
            handleDestinationOrAction(current.getAction(), ActionTrigger.BOOKMARK);
            // Recurse:
            extractBookmarkText(current);
            current = current.getNextSibling();
        }/* w w  w  . j  a v  a2s . co  m*/
        xhtml.endElement("ul");
    }
}

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/*from w  w  w  . ja  v  a2 s.c om*/
 *
 * @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();
    }
}