You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Custom Bookmark in .NET MAUI PDF Viewer control | Syncfusion
4
-
description: Learn here about the custom bookmark navigation in Syncfusion<sup>®</sup> .NET MAUI PDF Viewer (SfPdfViewer) control.
3
+
title: Custom Bookmarks in .NET MAUI PDF Viewer Control | Syncfusion
4
+
description: Discover how to navigate using custom bookmark navigation in Syncfusion<sup>®</sup> .NET MAUI PDF Viewer (SfPdfViewer) control.
5
5
platform: MAUI
6
6
control: SfPdfViewer
7
7
documentation: ug
8
8
---
9
9
10
-
# Custom bookmark in .NET MAUI PDF Viewer
10
+
# Custom Bookmarks in .NET MAUI PDF Viewer
11
11
12
-
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.
12
+
PDF documents can include custom bookmarks that allow the user to bookmark pages and navigate to them. The PDF viewer control displays these custom bookmarks in outline view.
13
13
14
-
## Showing/hiding the custom bookmark
14
+
## Showing/Hiding the Custom Bookmarks Pane
15
15
16
-
The PDF viewer's built-in custom bookmark view, which displays the custom bookmarks, can be shown or hidden using the [IsOutlineViewVisible](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_IsOutlineViewVisible) property. Its default value is `false`.
16
+
The built-in custom bookmark view of the PDF Viewer displays the custom bookmarks, can be shown or hidden using the [IsOutlineViewVisible](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_IsOutlineViewVisible) property. The default value of this property is `false`.
To access the custom bookmarks, you can use the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks)collection. This property provides the list of custom bookmarks in the PDF.
33
+
To retrieve the list of custom bookmarks in a PDF document, use the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) property.
34
34
35
35
{% tabs %}
36
36
{% highlight c# %}
@@ -40,19 +40,23 @@ var customBookmarks = pdfViewer.CustomBookmarks;
40
40
{% endhighlight %}
41
41
{% endtabs %}
42
42
43
-
## Add, edit, and remove custom bookmarks
43
+
## Add, Edit, and Remove Custom Bookmarks
44
44
45
-
To add, edit, or remove custom bookmarks in a PDF viewer, you can use the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_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.
45
+
You can manage custom bookmarks in the PDF viewer using the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) collection. This property allows you to add, edit, or remove bookmarks that appear in the viewer’s bookmark pane.
46
46
47
-
### Add custom bookmarks using the bookmark pane
47
+
### Add Custom Bookmarks
48
48
49
-
Custom bookmarks can be added using the floating button in the bookmark pane.
49
+
You can add custom bookmarks either through the UI or programmatically. You can also track additions using event handlers.
50
+
51
+
#### Add via UI
52
+
53
+
Use the floating action button in the bookmark pane to add a custom bookmark.
To add a custom bookmark, you can create a new instance of Bookmark and add it to the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) collection:
59
+
Create a new instance of the Bookmark class and add it to the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) collection:
56
60
57
61
{% tabs %}
58
62
{% highlight c# %}
@@ -65,19 +69,60 @@ Bookmark newBookmark = new Bookmark()
65
69
66
70
pdfViewer.CustomBookmarks.Add(newBookmark);
67
71
72
+
{% endhighlight %}
73
+
{% endtabs %}
74
+
75
+
#### Track Bookmark Additions
76
+
77
+
To track when a custom bookmark is added, subscribe to the [CollectionChanged](https://learn.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.observablecollection-1.collectionchanged?view=net-9.0) event of the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) collection inside the [DocumentLoaded](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_DocumentLoaded) event handler.
78
+
Within the [CollectionChanged](https://learn.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.observablecollection-1.collectionchanged?view=net-9.0) event handler, use the [NotifyCollectionChangedAction](https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.notifycollectionchangedaction?view=net-9.0) enumeration to determine the type of change. If the action is `Add`, iterate through `e.NewItems` to access the newly added bookmarks and perform any necessary tracking or logging.
79
+
80
+
{% tabs %}
81
+
{% highlight c# %}
82
+
83
+
// Event handler for when the PDF document is loaded
To rename an existing custom bookmark, you can retrieve the bookmark from the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) collection and modify its properties:
125
+
To rename an existing custom bookmark, retrieve it from the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) collection and update its Name property:
81
126
82
127
{% tabs %}
83
128
{% highlight c# %}
@@ -88,17 +133,93 @@ if (bookmarkToEdit != null)
88
133
bookmarkToEdit.Name = "Edited Bookmark Title";
89
134
}
90
135
136
+
{% endhighlight %}
137
+
{% endtabs %}
138
+
139
+
#### Track Bookmark Rename Changes
140
+
141
+
To track when a bookmark is renamed, you need to handle the [PropertyChanged](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged.propertychanged?view=net-9.0#system-componentmodel-inotifypropertychanged-propertychanged) event of each bookmark.
142
+
143
+
##### For Newly Added Bookmarks
144
+
145
+
Subscribe to the `PropertyChanged` event inside the [CollectionChanged](https://learn.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.observablecollection-1.collectionchanged?view=net-9.0) event handler when the action is **Add**:
Debug.WriteLine($"Bookmark updated: {e.PropertyName} changed to: " +
169
+
$"{changedBookmark.Name}");
170
+
}
171
+
}
172
+
}
173
+
174
+
{% endhighlight %}
175
+
{% endtabs %}
176
+
177
+
##### For Existing Bookmarks
178
+
179
+
To track rename changes for bookmarks that already exist when the document is loaded, wire the [PropertyChanged](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged.propertychanged?view=net-9.0#system-componentmodel-inotifypropertychanged-propertychanged) event for each bookmark in the [DocumentLoaded](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_DocumentLoaded) event handler:
Debug.WriteLine($"Bookmark updated: {e.PropertyName} changed to: " +
202
+
$"{changedBookmark.Name}");
203
+
}
204
+
}
205
+
}
91
206
92
207
{% endhighlight %}
93
208
{% endtabs %}
94
209
95
-
### Remove custom bookmarks using the bookmark context menu
210
+
### Remove Custom Bookmarks
211
+
212
+
You can remove custom bookmarks either through the UI or programmatically. You can also track bookmark removal using event handlers.
96
213
97
-
Tap the context menu button on the custom bookmark to be removed and tap `Delete`.
214
+
#### Remove via Context Menu
98
215
99
-
### Removing a Custom Bookmark programmatically
216
+
To remove a custom bookmark from the UI:
217
+
1. Tap the context menu button on the custom bookmark you want to delete.
218
+
2. Select Delete.
100
219
101
-
To remove a custom bookmark, you can remove it directly from the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) collection:
220
+
#### Remove Programmatically
221
+
222
+
To remove a custom bookmark programmatically, retrieve it from the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) collection and remove it:
102
223
103
224
{% tabs %}
104
225
{% highlight c# %}
@@ -109,21 +230,48 @@ if (bookmarkToRemove != null)
To track when a custom bookmark is removed, handle the [CollectionChanged](https://learn.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.observablecollection-1.collectionchanged?view=net-9.0) event of the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) collection. Use the [NotifyCollectionChangedAction](https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.notifycollectionchangedaction?view=net-9.0) enum to check if the action is `Remove`. If so, iterate through `e.OldItems` to access the removed bookmarks:
239
+
240
+
{% tabs %}
241
+
{% highlight c# %}
242
+
243
+
// Event handler for changes in the bookmarks collection
else if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems != null)
248
+
{
249
+
// Iterate through reomoved bookmarks
250
+
foreach (Bookmark bookmark in e.OldItems)
251
+
{
252
+
Debug.WriteLine($"Removed bookmark: {bookmark.Name} at page {bookmark.PageNumber}");
253
+
}
254
+
}
255
+
}
112
256
113
257
{% endhighlight %}
114
258
{% endtabs %}
115
259
116
-
## Navigating to a custom bookmark
260
+
## Navigate to a Custom Bookmark
261
+
262
+
You can navigate to custom bookmarks either through the UI or programmatically using the PDF viewer's built-in features.
117
263
118
-
### Navigating using UI
264
+
### Navigate Using UI
119
265
120
-
As mentioned above, you can show the outline view by setting the [IsOutlineViewVisible](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_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.
266
+
To navigate using the UI:
267
+
1. Ensure the outline view is visible by setting the [IsOutlineViewVisible](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_IsOutlineViewVisible) property to `true`.
268
+
2. Once the outline view is displayed, tap on any custom bookmark to navigate to the corresponding page.
121
269
122
270

123
271
124
-
### Navigating programmatically
272
+
### Navigate Programmatically
125
273
126
-
The PDF viewer allows the users to navigate to an custom bookmark using the [GoToBookmark](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_GoToBookmark_Syncfusion_Maui_PdfViewer_Bookmark_) method. The below code snippet illustrates the same.
274
+
To navigate to a custom bookmark programmatically, use the [GoToBookmark](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_GoToBookmark_Syncfusion_Maui_PdfViewer_Bookmark_) method. This method accepts a `Bookmark` object and navigates to the page associated with it.
0 commit comments