Navigation and Actions
Navigation and Actions
Aspose.PDF FOSS for .NET supports PDF navigation structures — bookmarks (outlines), page destinations, and document actions. These let you create interactive documents with table-of-contents navigation, cross-page links, and JavaScript triggers.
Document outlines (bookmarks)
OutlineCollection holds the document’s bookmark tree. Each
OutlineItemCollection is a bookmark entry with a title and destination.
using var doc = Document.Open(pdfBytes);
foreach (var item in doc.Outlines)
{
Console.WriteLine($"Bookmark: {item.Title}");
}Creating bookmarks
using var doc = Document.Open(pdfBytes);
var bookmark = new OutlineItemCollection(doc.Outlines);
bookmark.Title = "Chapter 1";
bookmark.Action = new GoToAction(doc.Pages[1]);
doc.Outlines.Add(bookmark);
doc.Save("with-bookmarks.pdf");GoTo actions
GoToAction navigates to a specific page and fit type within the same
document.
var goTo = new GoToAction(doc.Pages[3]);Named actions
NamedAction triggers predefined PDF viewer commands like NextPage,
PrevPage, FirstPage, and LastPage.
var nextPage = PdfAction.CreateNamed("NextPage");GoToRemote actions
GoToRemoteAction opens an external PDF file and navigates to a specific
page.
var remote = new GoToRemoteAction("other.pdf", 1);Launch actions
LaunchAction opens an external file (any format) from a PDF link.
var launch = new LaunchAction("readme.txt");Destination collections
DestinationCollection maps named destinations to pages, supporting
cross-reference navigation in large documents.
var dest = doc.Destinations;
int pageNum = dest.GetPageNumber("section2");Tips and Best Practices
- Build a bookmark tree that mirrors your document’s section hierarchy for intuitive navigation.
- Use
GoToActionwithFitTypeto control how the target page is displayed (fit width, fit page, etc.). - Named actions are viewer-dependent — stick to standard names (NextPage, PrevPage, FirstPage, LastPage).
- For cross-document links, use
GoToRemoteActionrather than URI actions pointing to PDF files. - Action collections on a page let you add multiple actions that fire on page open.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| Bookmark does not navigate | Action not set on the outline item | Assign a GoToAction to OutlineItemCollection.Action |
| GoTo action targets wrong page | Page index is 0-based internally but pages are 1-based | Use doc.Pages[n] directly in the GoToAction constructor |
| Named action has no effect | Viewer does not support the named action | Use standard names only |
FAQ
How do I create a table of contents?
Create OutlineItemCollection entries for each section, each with a
GoToAction targeting the section’s first page.
Can I nest bookmarks?
Yes. Add child OutlineItemCollection entries to a parent bookmark to create
a hierarchical outline.
What fit types are available for GoTo actions?
Fit, FitH (fit width), FitV (fit height), FitR (fit rectangle), and FitB (fit bounding box).
API Reference Summary
| Class / Method | Description |
|---|---|
OutlineCollection | Top-level bookmark collection on the document |
OutlineItemCollection | Single bookmark entry with title and action |
GoToAction | Navigate to a page within the same document |
GoToRemoteAction | Navigate to a page in an external PDF |
LaunchAction | Open an external file |
NamedAction | Trigger a predefined viewer command |
PdfAction.CreateGoTo | Factory for GoTo actions |
PdfAction.CreateNamed | Factory for named actions |
ActionCollection | Collection of actions on a page or annotation |
DestinationCollection | Named destination registry |
ActionType | Enumeration: GoTo, URI, JavaScript, Named, Launch |