Skip to content

Outline (Bookmarks)

Foxit PDF SDK for Android provides outline (bookmark) read, create, edit, and delete through the Core SDK. Outlines are organized as a tree; each node can have a title, destination, or action to help users navigate the document.

Built-in outline panel in UI Extensions

If you use the full reader (UI Extensions), outlines are built into the side panel (OutlineModule); users can view and tap nodes to jump to pages. No extra code is required.

Core Classes

ClassDescription
BookmarkOutline node; title, color, style, destination, and action
DestinationDestination; target page and zoom
ActionAction object; can attach to outline nodes (GoTo, URI, etc.)

Outline Tree Structure

Before traversing the tree, get the root with PDFDoc.getRootBookmark(). The root is abstract—it has no title and serves as the tree entry. If the document has no outline, create one with PDFDoc.createRootBookmark().

From the root, traverse with getFirstChild(), getNextSibling(), getParent(), and related methods.

Insert and Move Nodes

Use Bookmark.insert() to insert child or sibling nodes and moveTo() to relocate nodes.

Position Constants

ConstantValueDescription
e_PosFirstChild0As first child
e_PosLastChild1As last child
e_PosPrevSibling2Before previous sibling
e_PosNextSibling3After next sibling
e_PosFirstSibling4As first sibling
e_PosLastSibling5As last sibling

Style Constants

ConstantValueDescription
e_StyleNormal0x00Normal
e_StyleItalic0x01Italic
e_StyleBold0x02Bold

Destination

Destination defines zoom and visible area when jumping to a page. Create with static factory methods:

java
Destination.createXYZ(doc, pageIndex, left, top, zoomFactor)
Destination.createFitPage(doc, pageIndex)
Destination.createFitHorz(doc, pageIndex, top)
Destination.createFitVert(doc, pageIndex, left)
Destination.createFitRect(doc, pageIndex, left, bottom, right, top)
Destination.createFitBBox(doc, pageIndex)

Zoom Mode Constants

ConstantValueDescription
e_ZoomXYZ1Specified coordinates and zoom
e_ZoomFitPage2Fit entire page
e_ZoomFitHorz3Fit width
e_ZoomFitVert4Fit height
e_ZoomFitRect5Fit rectangle
e_ZoomFitBBox6Fit content bounding box

Example: Depth-First Traversal

java
import com.foxit.sdk.pdf.Bookmark;
import com.foxit.sdk.pdf.PDFDoc;
import com.foxit.sdk.pdf.actions.Destination;

PDFDoc doc = new PDFDoc("path/to/Sample.pdf");
doc.load(null);

Bookmark root = doc.getRootBookmark();
if (root != null && !root.isEmpty()) {
    traverseBookmarks(root.getFirstChild(), doc);
}

void traverseBookmarks(Bookmark bookmark, PDFDoc doc) throws PDFException {
    if (bookmark == null || bookmark.isEmpty()) return;

    String title = bookmark.getTitle();
    Destination dest = bookmark.getDestination();
    if (dest != null && !dest.isEmpty()) {
        int pageIndex = dest.getPageIndex(doc);
        int zoomMode = dest.getZoomMode();
    }

    // Recurse into children
    if (bookmark.hasChild()) {
        traverseBookmarks(bookmark.getFirstChild(), doc);
    }
    // Traverse siblings
    traverseBookmarks(bookmark.getNextSibling(), doc);
}

Example: Create Outline Nodes

java
PDFDoc doc = new PDFDoc("path/to/Sample.pdf");
doc.load(null);

Bookmark root = doc.getRootBookmark();
if (root == null || root.isEmpty()) {
    root = doc.createRootBookmark();
}

// Insert first child under root
Bookmark chapter1 = root.insert("第一章 概述", Bookmark.e_PosLastChild);
Destination dest = Destination.createFitPage(doc, 0);
chapter1.setDestination(dest);
chapter1.setColor(0x0000FF);
chapter1.setStyle(Bookmark.e_StyleBold);

// Insert child under chapter1
Bookmark section1 = chapter1.insert("1.1 背景", Bookmark.e_PosLastChild);
section1.setDestination(Destination.createXYZ(doc, 0, 0, 500, 1.0f));

doc.saveAs("path/to/output.pdf", PDFDoc.e_SaveFlagNormal);

API Reference

See the API Reference for full Bookmark, Destination, and Action documentation.