The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.

Bookmarks

  • 4 min to read

The PDF Document API provides properties and methods for generating new bookmarks or editing existing document's bookmarks in code.

Overview

A PdfBookmark class instance represents a bookmark. It can be accessed as an item of the PdfBookmark objects list returned by the PdfDocument.Bookmarks property. The PdfBookmark class contains the following properties to customize bookmarks:

Member Description
PdfBookmark.Action Provides access to the bookmark action being executed.
PdfBookmark.Children Gets or sets the collection of bookmark children for a document with a tree-structured hierarchy.
PdfBookmark.Destination Gets or sets a destination (a particular view of a document) to which a bookmark is referred to.
PdfBookmark.IsBold Gets or sets the value indicating whether the bookmark text is bold.
PdfBookmark.IsItalic Gets or sets the value indicating whether the bookmark text is italic.
PdfBookmark.IsInitiallyClosed Gets or sets a value that indicates whether bookmarks are initially closed (bookmark children are hidden) in the navigation panel after a document is loaded.
PdfBookmark.TextColor Gets or sets the color for a bookmark's text in the navigation pane.
PdfBookmark.Title Gets or sets the bookmark's text on the navigation pane.

Creating a Bookmark Destination

Call an overloaded PdfDocumentProcessor.CreateDestination method to create a destination to which a bookmark should be linked. The PDF Document API component can create following types of the destinations:

The created destination is assigned to the PdfBookmark.Destination property.

The overloaded PdfDocumentProcessor.CreateDestination methods use the world coordinate system. The world coordinate system's origin (0,0) is at the top left of the page. A positive x increases towards the right and a positive y towards the bottom. So, if you want to pass the page coordinates for a destination to one of the PdfDocumentProcessor.CreateDestination methods as arguments, you need to convert these page coordinates to world coordinates. See Coordinate Systems for more information.

When the overloaded PdfDocumentProcessor.CreateDestination methods create a destination represented by the PdfDestination object, the world coordinates are converted to page coordinates (see Coordinate Systems for details). To convert the world coordinates (units) into a physical value such as inches, these methods need the resolution's value (dpi) to be passed as dpiX and dpiY parameters. The default resolution is 96 dpi if no value is passed to these methods.

Since the measurement unit in the page coordinate system is a point (1/72 of an inch), pass 72 as dpiX and dpiY values to one of the PdfDocumentProcessor.CreateDestination methods.

Example

This example shows how to create bookmarks in code and add them to a document.

To do this:

Note

The measurement unit in the destination is equal to 1/72 of an inch.

using DevExpress.Pdf;

namespace AddBookmarks {
    class Program {
        static void Main(string[] args) {

            using (PdfDocumentProcessor processor = new PdfDocumentProcessor()) {

                // Load a document.
                processor.LoadDocument("..\\..\\Document.pdf");

                // Create bookmarks and add them to the PDF document.
                PdfDestination destination1 = processor.CreateDestination(1, 180, 150);
                PdfDestination destination2 = processor.CreateDestination(1, 168, 230);
                PdfDestination destination3 = processor.CreateDestination(1, 20, 350);
                processor.Document.Bookmarks.Add(new PdfBookmark() { Title = "PDF Document Processor", Destination = destination1 });
                processor.Document.Bookmarks.Add(new PdfBookmark() { Title = "Display, Print and Export PDF Documents", Destination = destination2 });
                processor.Document.Bookmarks.Add(new PdfBookmark() { Title = "Learn More", Destination = destination3 });

                // Save the result document.
                processor.SaveDocument("..\\..\\Result.pdf");
            }
        }
    }
}
See Also