Document outline in .NET MAUI PDF Viewer

11 Jun 20242 minutes to read

A PDF document may optionally have a document outline (also called as bookmarks) which allows the user to navigate from one part of the document to another. The PDF viewer control displays the document outline in a tree-structured hierarchy of outline elements.

Showing/hiding the outline view

The PDF viewer’s built-in outline view that displays the document outline in a tree like structure can be shown or hidden using the IsOutlineViewVisible property. The default value of this property is false.

<pdfViewer:SfPdfViewer x:Name="pdfViewer" IsOutlineViewVisible="{Binding OutlineViewVisible}" />
pdfViewer.IsOutlineViewVisible = true;

Accessing outline elements

To access the document outline and its elements, you can use the DocumentOutline property. This property provides a list of outline elements.

var documentOutline = pdfViewer.DocumentOutline;

Accessing nested child elements

The outline elements nested within each outline element can be accessed from the OutlineElement.Children property. Below code snippet illustrates accessing the 2nd element in the document outline. And then accessing its 3rd child.

OutlineElement outlineElement = pdfViewer.DocumentOutline[2];
OutlineElement nestedElement = outlineElement.Children[3];

As mentioned above, you can show the outline view by setting the IsOutlineViewVisible property to true. When the outline view is showing, you can tap on any element to navigate to the destination pointed by that element.

Document outline in .NET MAUI PDF Viewer

The PDF viewer allows the users to navigate to an outline element using the GoToOutlineElement method. The below code snippet illustrates the same.

//Get the required outline element
OutlineElement outlineElement = pdfViewer.DocumentOutline.Where(x => x.Title.Contains("Chapter 2")).FirstOrDefault();

if (outlineElement != null)
   pdfViewer.GoToOutlineElement(outlineElement);