- Showing/hiding the custom bookmark
- Accessing custom bookmarks collection
- Add , Edit and Remove custom bookmark
- Navigating to custom bookmark
Contact Support
Custom bookmark in .NET MAUI PDF Viewer
A PDF document may optionally have custom bookmarks that allow the user to bookmark pages and navigate to them. The PDF viewer control displays these custom bookmarks in outline view.
Showing/hiding the custom bookmark
The PDF viewer’s built-in custom bookmark view, which displays the custom bookmarks, can be shown or hidden using the IsOutlineViewVisible property. Its default value is false
.
<pdfViewer:SfPdfViewer x:Name="pdfViewer" IsOutlineViewVisible="{Binding OutlineViewVisible}" />
pdfViewer.IsOutlineViewVisible = true;
Accessing custom bookmarks collection
To access the custom bookmarks, you can use the CustomBookmarks collection. This property provides the list of custom bookmarks in the PDF.
var customBookmarks = pdfViewer.CustomBookmarks;
Add , Edit and Remove custom bookmark
To add, edit, or remove custom bookmarks in a PDF viewer, you can use the CustomBookmarks collection. This property provides access to the collection of custom bookmarks that can be manipulated to modify the bookmarks displayed in the viewer’s bookmark view.
Add custom bookmarks using the bookmark pane
Custom bookmarks can be added using the floating button in the bookmark pane.
Adding a Custom Bookmark programmatically
To add a custom bookmark, you can create a new instance of Bookmark and add it to the CustomBookmarks collection:
Bookmark newBookmark = new Bookmark()
{
Name = "New Bookmark",
PageNumber = 1, // Page number where the bookmark should to navigate
};
pdfViewer.CustomBookmarks.Add(newBookmark);
Rename custom bookmarks using the bookmark context menu
Tap the context menu button on the custom bookmark to be edited and choose Rename and enter the desired name.
Rename a Custom Bookmark programmatically
To rename an existing custom bookmark, you can retrieve the bookmark from the CustomBookmarks collection and modify its properties:
Bookmark bookmarkToEdit = pdfViewer.CustomBookmarks.FirstOrDefault(b => b.Title == "Chapter 2");
if (bookmarkToEdit != null)
{
bookmarkToEdit.Name = "Edited Bookmark Title";
}
Remove custom bookmarks using the bookmark context menu
Tap the context menu button on the custom bookmark to be removed and tap Delete
.
Removing a Custom Bookmark programmatically
To remove a custom bookmark, you can remove it directly from the CustomBookmarks collection:
Bookmark bookmarkToRemove = pdfViewer.CustomBookmarks.FirstOrDefault(b => b.Title == "Chapter 2");
if (bookmarkToRemove != null)
{
pdfViewer.CustomBookmarks.Remove(bookmarkToRemove);
}
Navigating to custom bookmark
Navigating using UI
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 bookmark to navigate to the destination pointed to that bookmark.
Navigating programmatically
The PDF viewer allows the users to navigate to an custom bookmark using the GoToBookmark method. The below code snippet illustrates the same.
//Get the required custom bookmark
Bookmark customBookmark = pdfViewer.CustomBookmarks.Where(x => x.Name.Contains("Chapter 2")).FirstOrDefault();
if (customBookmark != null)
pdfViewer.GoToBookmark(customBookmark);