Skip to content

Commit 2373c33

Browse files
committedJun 18, 2025·
Addressed the review suggestion .
1 parent 4860162 commit 2373c33

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed
 

‎Annotations/PdfViewerAnnotations/PdfViewerAnnotations/MainPage.xaml.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public MainPage()
1010
{
1111
InitializeComponent();
1212
Stream? stream = typeof(MainPage).GetTypeInfo().Assembly.GetManifestResourceStream("PdfViewerAnnotations.Assets.Annotations.pdf");
13-
PDFViewer.LoadDocument(stream);
13+
if (stream != null)
14+
PDFViewer.LoadDocument(stream);
1415
}
1516

1617
private void AddHighlightAnnotation(object sender, EventArgs e)
@@ -44,36 +45,47 @@ private void RemoveAnnotation(object sender, EventArgs e)
4445
//Obtain the annotation collection.
4546
ReadOnlyObservableCollection<Annotation> annotations = PDFViewer.Annotations;
4647

47-
//Obtain the first annotation in the annotation collection.
48-
Annotation firstAnnotation = annotations[3];
48+
if (annotations != null && annotations.Count > 3 && annotations[3] != null)
49+
{
4950

50-
//Remove the annotation using RemoveAnnotation method of `SfPdfViewer`.
51-
PDFViewer.RemoveAnnotation(firstAnnotation);
51+
//Obtain the annotation in the annotation collection.
52+
Annotation annotation = annotations[3];
53+
54+
//Remove the annotation using RemoveAnnotation method of `SfPdfViewer`.
55+
PDFViewer.RemoveAnnotation(annotation);
56+
}
5257
}
5358

5459
void EditAnnotation(object sender, EventArgs e)
5560
{
5661
// Obtain the annotation collection using
5762
ReadOnlyObservableCollection<Annotation> annotations = PDFViewer.Annotations;
5863

59-
// Obtain the first annotation in the annotation collection.
60-
Annotation annotation = annotations[4];
64+
if (annotations != null && annotations.Count > 4 && annotations[4] != null)
65+
{
66+
67+
// Obtain the first annotation in the annotation collection.
68+
Annotation annotation = annotations[4];
69+
70+
// Edit the annotation properties.
71+
annotation.Color = Colors.Green; //Stroke color.
72+
annotation.Opacity = 0.75f; // 75% Opacity
6173

62-
// Edit the annotation properties.
63-
annotation.Color = Colors.Green; //Stroke color.
64-
annotation.Opacity = 0.75f; // 75% Opacity
74+
}
6575
}
6676

6777
void PerformUndo(object sender, EventArgs e)
6878
{
6979
// Undo the last operation using the UndoCommand of `SfPdfViewer` instance.
70-
PDFViewer.UndoCommand!.Execute(true);
80+
if (PDFViewer.UndoCommand != null)
81+
PDFViewer.UndoCommand.Execute(true);
7182
}
7283

7384
void PerformRedo(object sender, EventArgs e)
7485
{
7586
// Redo the last operation using the RedoCommand of `SfPdfViewer` instance.
76-
PDFViewer.RedoCommand!.Execute(true);
87+
if (PDFViewer.RedoCommand != null)
88+
PDFViewer.RedoCommand.Execute(true);
7789
}
7890
}
7991

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Working with Annotations in .NET MAUI PDF Viewer
2+
3+
This repository provides an example of how to add, edit, remove, and manage annotations in a PDF document using the **Syncfusion .NET MAUI PDF Viewer**, allowing users to interactively modify annotations within a PDF.
4+
5+
## Process behind PDF annotation management
6+
7+
The sample demonstrates how annotations can be programmatically created and modified directly within the loaded PDF document. Users can add highlight annotations to specific text areas, change annotation properties such as color and opacity, remove existing annotations, and use undo/redo actions to manage recent annotation changes.
8+
9+
## Steps to use the sample
10+
11+
1. Run the application to load a sample PDF document embedded in the project.
12+
2. Use the toolbar buttons to perform various annotation actions:
13+
- **Add Annotation**: Inserts a new highlight annotation on a specified page location.
14+
- **Remove Annotation**: Removes a specific annotation from the document.
15+
- **Edit Annotation**: Changes the appearance of an existing annotation.
16+
- **Undo Annotation**: Reverts the most recent annotation change.
17+
- **Redo Annotation**: Re-applies the last undone annotation change.

0 commit comments

Comments
 (0)
Please sign in to comment.