How to: Add Bookmarks to a Document
- 2 minutes to read
Important
You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.
This example shows how to create bookmarks in code and add them to a document.
To do this:
- Create a PdfBookmark object;
- Specify the bookmark title and destination using the PdfBookmark.Title and PdfBookmark.Destination properties. To create a destination, call a PdfDocumentProcessor.CreateDestination overloaded method.
- Add the bookmark to the bookmarks collection, which is accessed from the PdfDocument.Bookmarks property.
Note
The measurement unit in the destination is equal to 1/72 of an inch.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-add-bookmarks-to-a-document-t495077
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