Navigate PDF outline tree on Server/Desktop

The basic code needed to navigate an outline tree and print its result:

1void PrintIndent(Bookmark item) throws PDFNetException {
2 int ident = item.getIndent() - 1;
3 for (int i = 0; i < ident; ++i) {
4 System.out.print(" ");
5 }
6}
7void PrintOutlineTree(Bookmark item) throws PDFNetException {
8 for (; item.isValid(); item = item.getNext()) {
9 PrintIndent(item);
10 System.out.print((item.isOpen() ? "- " : "+ ") + item.getTitle() + " ACTION -> ");
11 if (item.hasChildren()) {
12 PrintOutlineTree(item.getFirstChild());
13 }
14 }
15}
16PDFDoc doc = new PDFDoc(filename);
17Bookmark root = doc.getFirstBookmark();
18PrintOutlineTree(root);

Read, add, edit PDF outlines and bookmarks - Full Sample
Full code sample which illustrates how to read and edit existing outline items and create new bookmarks using the high-level API. Samples available in Python, C# (.Net), C++, Go, Java, Node.js (JavaScript), PHP, Ruby, VB. To use this code, you'll need to download and get started with Server SDK.

About outline tree

A PDF document may display a document outline on the screen, allowing the user to navigate interactively from one part of the document to another. The outline consists of a tree-structured hierarchy of Bookmarks (sometimes called outline items), which serve as a "visual table of contents" to display the document's structure to the user.

Each Bookmark has a title that appears on screen, and an Action that specifies what happens when a user clicks on the Bookmark. The typical Action for a user-created Bookmark is to move to another location in the current document — although any Action can be specified.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales