Navigate PDF outline tree on Server/Desktop

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

1def PrintIndent(item):
2 indent = item.GetIndent() - 1
3 i = 0
4 while i < indent:
5 sys.stdout.write(" ")
6 i = i + 1
7def PrintOutlineTree (item):
8 while item.IsValid():
9 PrintIndent(item)
10 if item.IsOpen():
11 sys.stdout.write("- " + item.GetTitle() + " ACTION -> ")
12 else:
13 sys.stdout.write("+ " + item.GetTitle() + " ACTION -> ")
14 if item.HasChildren():
15 PrintOutlineTree(item.GetFirstChild())
16 item = item.GetNext()
17doc = PDFDoc(filename)
18root = doc.GetFirstBookmark()
19PrintOutlineTree(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