Navigate PDF outline tree on Server/Desktop

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

1func PrintIndent(item Bookmark){
2 indent := item.GetIndent() - 1
3 i := 0
4 for i < indent{
5 os.Stdout.Write([]byte(" "))
6 i = i + 1
7 }
8}
9func PrintOutlineTree (item Bookmark){
10 for item.IsValid(){
11 PrintIndent(item)
12 if item.IsOpen(){
13 os.Stdout.Write([]byte("- " + item.GetTitle() + " ACTION -> "))
14 }else{
15 os.Stdout.Write([]byte("+ " + item.GetTitle() + " ACTION -> "))
16 }
17 if item.HasChildren(){
18 PrintOutlineTree(item.GetFirstChild())
19 }
20 item = item.GetNext()
21 }
22}
23doc := NewPDFDoc(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