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 do
5 print " "
6 i = i + 1
7 end
8end
9def PrintOutlineTree (item)
10 while item.IsValid() do
11 PrintIndent(item)
12 if item.IsOpen()
13 print( "- " + item.GetTitle() + " ACTION -> ")
14 else
15 print("+ " + item.GetTitle() + " ACTION -> ")
16 end
17 if item.HasChildren()
18 PrintOutlineTree(item.GetFirstChild())
19 end
20 item = item.GetNext()
21 end
22end
23doc = PDFDoc.new(filename)
24root = doc.GetFirstBookmark()
25PrintOutlineTree(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