Skip to content

Commit a178678

Browse files
authored
Update Custom-Bookmark.md
1 parent 4e9cf8c commit a178678

File tree

1 file changed

+61
-34
lines changed

1 file changed

+61
-34
lines changed

MAUI/PDF-Viewer/Custom-Bookmark.md

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
---
22
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.
55
platform: MAUI
66
control: SfPdfViewer
77
documentation: ug
88
---
99

1010
# Custom Bookmarks in .NET MAUI PDF Viewer
1111

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.
1313

1414
## Showing/Hiding the Custom Bookmarks Pane
1515

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`.
1717

1818
{% tabs %}
1919
{% highlight XAML %}
@@ -30,7 +30,7 @@ pdfViewer.IsOutlineViewVisible = true;
3030

3131
## Accessing the Custom Bookmarks Collection
3232

33-
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.
3434

3535
{% tabs %}
3636
{% highlight c# %}
@@ -42,17 +42,21 @@ var customBookmarks = pdfViewer.CustomBookmarks;
4242

4343
## Add, Edit, and Remove Custom Bookmarks
4444

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 viewers bookmark pane.
4646

47-
### Add Custom Bookmarks From UI
47+
### Add Custom Bookmarks
4848

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.
5054

5155
![Custom bookmark floating button](Images\custom-bookmark.png)
5256

53-
### Add a Custom Bookmark Programmatically
57+
#### Add Programmatically
5458

55-
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:
5660

5761
{% tabs %}
5862
{% highlight c# %}
@@ -65,13 +69,13 @@ Bookmark newBookmark = new Bookmark()
6569

6670
pdfViewer.CustomBookmarks.Add(newBookmark);
6771

68-
6972
{% endhighlight %}
7073
{% endtabs %}
7174

72-
### Tracking Addition of Custom Bookmark
75+
#### Track Bookmark Additions
7376

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.
7579

7680
{% tabs %}
7781
{% highlight c# %}
@@ -89,9 +93,10 @@ private void PdfViewer_DocumentLoaded(object? sender, EventArgs? e)
8993
// Event handler for changes in the bookmarks collection
9094
private void Bookmarks_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
9195
{
92-
// Handle addition of new bookmarks
96+
Check if the change action is 'Add'
9397
if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
9498
{
99+
// Iterate through newly added bookmarks
95100
foreach (Bookmark bookmark in e.NewItems)
96101
{
97102
Debug.WriteLine($"Added bookmark: {bookmark.Name} at page {bookmark.PageNumber}");
@@ -102,14 +107,22 @@ private void Bookmarks_CollectionChanged(object? sender, NotifyCollectionChanged
102107
{% endhighlight %}
103108
{% endtabs %}
104109

105-
### Rename Custom Bookmarks Using Context Menu
110+
### Rename Custom Bookmarks
111+
112+
You can rename custom bookmarks either through the UI or programmatically. You can also track rename changes using event handlers.
113+
114+
#### Rename via Context Menu
115+
116+
To rename a custom bookmark from the UI:
117+
1. Tap the context menu button on the desired custom bookmark.
118+
2. Select **Rename**.
119+
3. Enter the new name.
106120

107-
Tap the context menu button on the custom bookmark to be edited and choose Rename and enter the desired name.
108121
![Custom bookmark context menu](Images\custom-bookmark-contextmenu.png)
109122

110-
### Rename a Custom Bookmark Programmatically
123+
#### Rename Programmatically
111124

112-
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:
113126

114127
{% tabs %}
115128
{% highlight c# %}
@@ -120,13 +133,16 @@ if (bookmarkToEdit != null)
120133
bookmarkToEdit.Name = "Edited Bookmark Title";
121134
}
122135

123-
124136
{% endhighlight %}
125137
{% endtabs %}
126138

127-
### Tracking Custom Bookmarks Rename Changes
139+
#### Track Bookmark Rename Changes
128140

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**:
130146

131147
{% tabs %}
132148
{% highlight c# %}
@@ -158,7 +174,9 @@ private void Bookmark_PropertyChanged(object? sender, PropertyChangedEventArgs e
158174
{% endhighlight %}
159175
{% endtabs %}
160176

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:
162180

163181
{% tabs %}
164182
{% highlight c# %}
@@ -189,13 +207,19 @@ private void Bookmark_PropertyChanged(object? sender, PropertyChangedEventArgs e
189207
{% endhighlight %}
190208
{% endtabs %}
191209

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.
193213

194-
Tap the context menu button on the custom bookmark to be removed and tap `Delete`.
214+
#### Remove via Context Menu
195215

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.
197219

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:
199223

200224
{% tabs %}
201225
{% highlight c# %}
@@ -206,13 +230,12 @@ if (bookmarkToRemove != null)
206230
pdfViewer.CustomBookmarks.Remove(bookmarkToRemove);
207231
}
208232

209-
210233
{% endhighlight %}
211234
{% endtabs %}
212235

213-
### Tracking Removal of Custom Bookmark
236+
#### Track Bookmark Removal
214237

215-
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:
216239

217240
{% tabs %}
218241
{% highlight c# %}
@@ -233,17 +256,21 @@ private void Bookmarks_CollectionChanged(object? sender, NotifyCollectionChanged
233256
{% endhighlight %}
234257
{% endtabs %}
235258

236-
## Navigation to a Custom Bookmark
259+
## Navigate to a Custom Bookmark
260+
261+
You can navigate to custom bookmarks either through the UI or programmatically using the PDF viewer's built-in features.
237262

238-
### Navigation using UI
263+
### Navigate Using UI
239264

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.
241268

242269
![Custom bookmark in .NET MAUI PDF Viewer](Images\custom-bookmark.png)
243270

244-
### Navigation to a Custom Bookmark Programmatically
271+
### Navigate Programmatically
245272

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.
247274

248275
{% tabs %}
249276
{% highlight c# %}

0 commit comments

Comments
 (0)