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
Copy file name to clipboardExpand all lines: MAUI/PDF-Viewer/Custom-Bookmark.md
+61-34Lines changed: 61 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,19 @@
1
1
---
2
2
layout: post
3
-
title: Custom Bookmarks 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
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
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# %}
@@ -42,17 +42,21 @@ var customBookmarks = pdfViewer.CustomBookmarks;
42
42
43
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 From UI
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,13 +69,13 @@ Bookmark newBookmark = new Bookmark()
65
69
66
70
pdfViewer.CustomBookmarks.Add(newBookmark);
67
71
68
-
69
72
{% endhighlight %}
70
73
{% endtabs %}
71
74
72
-
###Tracking Addition of Custom Bookmark
75
+
#### Track Bookmark Additions
73
76
74
-
In the [DocumentLoaded](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_DocumentLoaded) event handler, 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 to track changes while addition of custom bookmark in it. Within the [CollectionChanged](https://learn.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.observablecollection-1.collectionchanged?view=net-9.0) event handler, you use the [NotifyCollectionChangedAction](https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.notifycollectionchangedaction?view=net-9.0) enum to determine if the action is `Add`. If so, you iterate through all items in e.NewItems to track the addition of custom bookmark.
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.
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:
113
126
114
127
{% tabs %}
115
128
{% highlight c# %}
@@ -120,13 +133,16 @@ if (bookmarkToEdit != null)
120
133
bookmarkToEdit.Name = "Edited Bookmark Title";
121
134
}
122
135
123
-
124
136
{% endhighlight %}
125
137
{% endtabs %}
126
138
127
-
###Tracking Custom Bookmarks Rename Changes
139
+
#### Track Bookmark Rename Changes
128
140
129
-
For the newly added custom bookmarks, you need to wire the [PropertyChanged](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged.propertychanged?view=net-9.0#system-componentmodel-inotifypropertychanged-propertychanged) event in the [CollectionChanged](https://learn.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.observablecollection-1.collectionchanged?view=net-9.0) event handler after checking whether the action is `Add` using the [NotifyCollectionChangedAction](https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.notifycollectionchangedaction?view=net-9.0) enum.
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**:
130
146
131
147
{% tabs %}
132
148
{% highlight c# %}
@@ -158,7 +174,9 @@ private void Bookmark_PropertyChanged(object? sender, PropertyChangedEventArgs e
158
174
{% endhighlight %}
159
175
{% endtabs %}
160
176
161
-
For the existing custom bookmark, you can track the bookmark rename changes by wiring the [PropertyChanged](https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged.propertychanged?view=net-9.0#system-componentmodel-inotifypropertychanged-propertychanged) event using the event handler in the [DocumentLoaded](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_DocumentLoaded) event handler for all existing custom bookmarks in the [CustomBookmarks](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html#Syncfusion_Maui_PdfViewer_SfPdfViewer_CustomBookmarks) collection, where you can track each custom bookmark rename changes.
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:
162
180
163
181
{% tabs %}
164
182
{% highlight c# %}
@@ -189,13 +207,19 @@ private void Bookmark_PropertyChanged(object? sender, PropertyChangedEventArgs e
189
207
{% endhighlight %}
190
208
{% endtabs %}
191
209
192
-
### Remove Custom Bookmarks Using 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.
193
213
194
-
Tap the context menu button on the custom bookmark to be removed and tap `Delete`.
214
+
#### Remove via Context Menu
195
215
196
-
### Remove 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.
197
219
198
-
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:
199
223
200
224
{% tabs %}
201
225
{% highlight c# %}
@@ -206,13 +230,12 @@ if (bookmarkToRemove != null)
In the [CollectionChanged](https://learn.microsoft.com/en-us/dotnet/api/system.collections.objectmodel.observablecollection-1.collectionchanged?view=net-9.0) event handler, you can use the [NotifyCollectionChangedAction](https://learn.microsoft.com/en-us/dotnet/api/system.collections.specialized.notifycollectionchangedaction?view=net-9.0) enum to determine if the action is `Remove`. If it is, you iterate through all items in e.OldItems to track the removal of custom bookmark.
238
+
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:
You can navigate to custom bookmarks either through the UI or programmatically using the PDF viewer's built-in features.
237
262
238
-
### Navigation using UI
263
+
### Navigate Using UI
239
264
240
-
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.
265
+
To navigate using the UI:
266
+
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`.
267
+
2. Once the outline view is displayed, tap on any custom bookmark to navigate to the corresponding page.
241
268
242
269

243
270
244
-
### Navigation to a Custom Bookmark Programmatically
271
+
### Navigate Programmatically
245
272
246
-
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.
273
+
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