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
| Class | Description |
|---|---|
Bookmark | Outline node; title, color, style, destination, and action |
Destination | Destination; target page and zoom |
Action | Action 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
| Constant | Value | Description |
|---|---|---|
e_PosFirstChild | 0 | As first child |
e_PosLastChild | 1 | As last child |
e_PosPrevSibling | 2 | Before previous sibling |
e_PosNextSibling | 3 | After next sibling |
e_PosFirstSibling | 4 | As first sibling |
e_PosLastSibling | 5 | As last sibling |
Style Constants
| Constant | Value | Description |
|---|---|---|
e_StyleNormal | 0x00 | Normal |
e_StyleItalic | 0x01 | Italic |
e_StyleBold | 0x02 | Bold |
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
| Constant | Value | Description |
|---|---|---|
e_ZoomXYZ | 1 | Specified coordinates and zoom |
e_ZoomFitPage | 2 | Fit entire page |
e_ZoomFitHorz | 3 | Fit width |
e_ZoomFitVert | 4 | Fit height |
e_ZoomFitRect | 5 | Fit rectangle |
e_ZoomFitBBox | 6 | Fit 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.