Requirements These packages are required to use these features in production. Trial keys have unlimited access to all features.
View DemoThe basic code needed to navigate an outline tree and print its result:
C# C++ Go Java JavaScript Obj-C PHP Python Ruby VB
1 void PrintIdent ( Bookmark item )
2 {
3 int ident = item. GetIdent () - 1 ;
4 for ( int i = 0 ; i < ident; ++ i) {
5 Console. Write ( " " );
6 }
7 }
8 void PrintOutlineTree ( Bookmark item )
9 {
10 for (; item. IsValid (); item = item. GetNext ()) {
11 PrintIdent (item);
12 Console. Write ( " {0:s}{1:s} ACTION -> " , (item. IsOpen () ? " - " : " + " ), item. GetTitle ());
13 if (item. HasChildren ()) {
14 PrintOutlineTree (item. GetFirstChild ());
15 }
16 }
17 }
18 PDFDoc doc = new PDFDoc (filename);
19 Bookmark root = doc. GetFirstBookmark ();
20 PrintOutlineTree (root);
1 void PrintIndent ( Bookmark item )
2 {
3 int ident = item. GetIndent () - 1 ;
4 for ( int i = 0 ; i < ident; ++ i) {
5 cout << " " ;
6 }
7 }
8 void PrintOutlineTree ( Bookmark item )
9 {
10 for (; item. IsValid (); item = item. GetNext ()) {
11 PrintIndent (item);
12 cout << (item. IsOpen () ? " - " : " + " ) << item. GetTitle () << " ACTION -> " ;
13 if (item. HasChildren ()) {
14 PrintOutlineTree (item. GetFirstChild ());
15 }
16 }
17 }
18 PDFDoc doc ( filename );
19 Bookmark root = doc. GetFirstBookmark ();
20 PrintOutlineTree (root);
1 func 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 }
9 func 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 }
23 doc := NewPDFDoc (filename)
24 root := doc. GetFirstBookmark ()
25 PrintOutlineTree (root)
1 void 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 }
7 void 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 }
16 PDFDoc doc = new PDFDoc (filename);
17 Bookmark root = doc. getFirstBookmark ();
18 PrintOutlineTree (root);
1 async function main () {
2 const printIndent = async ( item , str ) => {
3 const ident = ( await item. getIndent ()) - 1 ;
4 for ( let i = 0 ; i < ident; ++ i) {
5 str += ' ' ;
6 }
7 return str;
8 };
9 const printOutlineTree = async ( item ) => {
10 for (; item != null ; item = await item. getNext ()) {
11 let IndentString = await printIndent (item, IndentString);
12 let TitleString = await item. getTitle ();
13 console. log (IndentString + ( await item. isOpen ()) ? ' - ' : ' + ' ) + TitleString + ' Action -> ' );
14 if ( await item. hasChildren ()) {
15 await printOutlineTree ( await item. getFirstChild ());
16 }
17 }
18 };
19 const doc = await PDFNet.PDFDoc. createFromURL (filename);
20 const root = await docOut. getFirstBookmark ();
21 await printOutlineTree (root);
22 }
23 PDFNet. runWithCleanup (main);
1 void PrintIndent (PTBookmark * item )
2 {
3 int ident = [item GetIndent ] - 1 ;
4 for ( int i = 0 ; i < ident; ++ i) {
5 printf ( " " );
6 }
7 }
8 void PrintOutlineTree (PTBookmark * item )
9 {
10 for (; [item IsValid ]; item = [item GetNext ]) {
11 PrintIndent (item);
12 if ([item IsOpen ]) {
13 printf ( " - %s ACTION -> " , [[item GetTitle ] UTF8String ]);
14 }
15 else {
16 printf ( " + %s ACTION -> " , [[item GetTitle ] UTF8String ]);
17 }
18 if ([item HasChildren ]) {
19 PrintOutlineTree ([item GetFirstChild ]);
20 }
21 }
22 }
23 PTPDFDoc * doc = [[PTPDFDoc alloc ] initWithFilepath : filename];
24 PTBookmark * root = [doc GetFirstBookmark ];
25 PrintOutlineTree (root);
1 function PrintIndent ($item) {
2 $ident = $item -> GetIndent () - 1 ;
3 for ($i = 0 ; $i < $ident; ++ $i) {
4 echo " " ;
5 }
6 }
7 function PrintOutlineTree ($item) {
8 for (; $item -> IsValid (); $item = $item -> GetNext ()) {
9 PrintIndent ($item);
10 echo ($item -> IsOpen () ? " - " : " + " ) . $item -> GetTitle () . " ACTION -> " ;
11 if ($item -> HasChildren ()) {
12 PrintOutlineTree ($item -> GetFirstChild ());
13 }
14 }
15 }
16 $doc = new PDFDoc ($filename);
17 $root = $doc -> GetFirstBookmark ();
18 PrintOutlineTree ($root);
1 def PrintIndent ( item ):
2 indent = item.GetIndent() - 1
3 i = 0
4 while i < indent:
5 sys.stdout.write( " " )
6 i = i + 1
7 def 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()
17 doc = PDFDoc(filename)
18 root = doc.GetFirstBookmark()
19 PrintOutlineTree(root)
1 def PrintIndent ( item )
2 indent = item. GetIndent () - 1
3 i = 0
4 while i < indent do
5 print " "
6 i = i + 1
7 end
8 end
9 def 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
22 end
23 doc = PDFDoc . new (filename)
24 root = doc. GetFirstBookmark ()
25 PrintOutlineTree (root)
1 Sub PrintIndent ( ByVal item As Bookmark )
2 Dim indent As Integer = item . GetIndent () - 1
3 Dim i As Integer
4 For i = 1 To indent
5 Console. Write ( " " )
6 Next
7 End Sub
8 Public Shared Sub PrintOutlineTree (ByVal item As Bookmark )
9 Do While item . IsValid ()
10 PrintIndent ( item )
11 If item .IsOpen Then
12 Console. Write ( " - {0:s} ACTION -> " , item . GetTitle ())
13 Else
14 Console. Write ( " + {0:s} ACTION -> " , item . GetTitle ())
15 End If
16 If item . HasChildren () Then ' Recursively print children sub-trees
17 PrintOutlineTree ( item . GetFirstChild ())
18 End If
19 item = item . GetNext ()
20 Loop
21 End Sub
22 Dim doc As PDFDoc = New PDFDoc (filename)
23 Dim root As Bookmark = doc1. GetFirstBookmark ()
24 PrintOutlineTree (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 .
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.