Click or drag to resize

Get access, create and manipulate bookmarks

This topic contains the following sections:

Overview

A PDF document may optionally 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 outline items (sometimes called bookmarks), which serve as a visual table of contents to display the document’s structure to the user.

Bookmarks it is a tree-structured hierarchy. Clicking the text of any visible bookmark activates it, causing the viewer application to jump to a destination or trigger an action associated with the bookmark.

Open in full size

Bookmarks
How to find and list all bookmarks of a PDF
C#
public void TraverseBookmark(PdfBookmarkCollections bookmarks, int iLevel)
{
    foreach (var item in bookmarks)
    {
        TraverseBookmark(item.Childs, iLevel + 1);
    }
}
    //...

    using (var doc = PdfDocument.Load("sample.pdf"))
    {
        TraverseBookmark(doc.Bookmarks, 0);
    }
Bookmark page index in an existing PDF document
C#
using (var doc = PdfDocument.Load("sample"))
{
    // Create explicit destination that display the page designated by pageIndex in the document designated by doc
    int pageIndex = 3;
    PdfDestination dest = PdfDestination.CreateXYZ(doc, pageIndex);

    //Insert destination into bookmark collection
    doc.Bookmarks.InsertAt(0, "Bookmark for page #3", dest);

    //Save a copy of PDF document
    doc.Save("sample_with_bookmarks.pdf", SaveFlags.NoIncremental);
}
Bookmark page index in an remote PDF document
C#
using (var doc = PdfDocument.Load("sample"))
{
    // Create explicit destination that display the page designated by pageIndex in the remote document
    int pageIndex = 3;
    PdfDestination dest = PdfDestination.CreateXYZ(null, pageIndex);

    //Create a file specification that points to an external document.
    var fileSpec = new PdfFileSpecification(doc);
    fileSpec.FileName = @"c:\other_document.pdf";

    //Create a GoToR action
    var action = new PdfGoToRAction(doc, fileSpec, dest);

    //Insert action into bookmark collection
    doc.Bookmarks.InsertAt(0, "Bookmark for page #3 in other document", action);

    //Save a copy of PDF document
    doc.Save("sample_with_bookmarks.pdf", SaveFlags.NoIncremental);
}
See Also