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 GoToAction with FitType to 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 GoToRemoteAction rather than URI actions pointing to PDF files.
  • Action collections on a page let you add multiple actions that fire on page open.

Common Issues

IssueCauseFix
Bookmark does not navigateAction not set on the outline itemAssign a GoToAction to OutlineItemCollection.Action
GoTo action targets wrong pagePage index is 0-based internally but pages are 1-basedUse doc.Pages[n] directly in the GoToAction constructor
Named action has no effectViewer does not support the named actionUse 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 / MethodDescription
OutlineCollectionTop-level bookmark collection on the document
OutlineItemCollectionSingle bookmark entry with title and action
GoToActionNavigate to a page within the same document
GoToRemoteActionNavigate to a page in an external PDF
LaunchActionOpen an external file
NamedActionTrigger a predefined viewer command
PdfAction.CreateGoToFactory for GoTo actions
PdfAction.CreateNamedFactory for named actions
ActionCollectionCollection of actions on a page or annotation
DestinationCollectionNamed destination registry
ActionTypeEnumeration: GoTo, URI, JavaScript, Named, Launch

See Also