officefileapi-114957-pdf-document-api-additional-content-bookmarks.md
Bookmarks (outlines) are used to quickly navigate from one part of a document to another. Bookmarks can be anchored to the document page or external URI. The PDF Document API allows you to manage bookmarks.
Use the PdfDocument.Bookmarks property to obtain a list of bookmarks (PdfBookmark objects). Call the Add(T) method to add a new bookmark. The Remove(T) method call removes the specified bookmark.
Note
PDF Document API does not create bookmarks anchored to an action.
Use the PdfBookmark.Destination property to assign a bookmark to a destination – reference to a page with specific view parameters.
A destination includes the following view parameters:
Call one of the following methods to create a destination:
| View Parameters | Methods |
|---|---|
| Fit the page’s bounding box to the document window both horizontally and vertically. | PdfPageFacade.CreateFitBBoxDestination |
| Fit the page’s bounding box to the document window horizontally. | PdfPageFacade.CreateFitBBoxHorizontallyDestination |
| Fit the page’s bounding box to the document window vertically. | PdfPageFacade.CreateFitBBoxVerticallyDestination |
| Fit the entire page to the document window both horizontally and vertically ( Zoom to Page Level view). | PdfPageFacade.CreateFitDestination |
| Fit the entire page to the document window horizontally. | PdfPageFacade.CreateFitHorizontallyDestination |
| Fit the entire page to the document window vertically. | PdfPageFacade.CreateFitVerticallyDestination |
| Display the specified page area in the document window. | PdfPageFacade.CreateFitRectangleDestination |
| Position the specified page coordinate at the top left document window corner, and specify the zoom factor. | PdfPageFacade.CreateXYZDestination |
The following code snippet creates a bookmark with a destination that displays the eighth page as follows:
using (PdfDocumentProcessor pdfDocumentProcessor = new PdfDocumentProcessor())
{
// Load a document
pdfDocumentProcessor.LoadDocument("Demo.pdf");
// Create a FitB destination that refers to the eighth page
PdfFitBBoxDestination destination =
new PdfFitBBoxDestination(pdfDocumentProcessor.Document.Pages[7]);
// Create a bookmark
PdfBookmark bookmark = new PdfBookmark();
bookmark.Title = "Annotations";
// Associate the bookmark with the created destination
bookmark.Destination = destination;
// Add the bookmark to the document collection
pdfDocumentProcessor.Document.Bookmarks.Add(bookmark);
// Save the result
pdfDocumentProcessor.SaveDocument("out.pdf");
}
Using pdfDocumentProcessor As New PdfDocumentProcessor()
' Load a document
pdfDocumentProcessor.LoadDocument("Demo.pdf")
' Create a FitB destination that refers to the eighth page
Dim destination As New PdfFitBBoxDestination
(pdfDocumentProcessor.Document.Pages(1))
' Create a bookmark
Dim bookmark As New PdfBookmark()
bookmark.Title = "Annotations"
' Associate the bookmark with the created destination
bookmark.Destination = destination
' Add a bookmark to the document collection
pdfDocumentProcessor.Document.Bookmarks.Add(bookmark)
' Save the result
pdfDocumentProcessor.SaveDocument("out.pdf")
End Using
See Also
Configure Links in PDF Files with DevExpress PDF Document API