From 969dd4975ddbc34c036c0ae62758d71da9772929 Mon Sep 17 00:00:00 2001 From: Krithika Date: Thu, 18 Jul 2024 19:48:10 +0530 Subject: [PATCH 1/4] 883474 Need to include adding annotation topic under programmatic support --- ...rking-with-Annotations-Programmatically.md | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md b/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md index dd08a438e5..83bcbe9add 100644 --- a/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md +++ b/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md @@ -8,6 +8,53 @@ documentation: ug --- # Working with annotations programmatically +## Add an annotation + +PDF Viewer allows the users to add the annotation programmatically without user interaction. We can add the annotation to the PDF document with the help of the [PdfViewerControl’s loadedDocument](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_LoadedDocument) property from the code behind. + +The following code snippet explains how to add an ink annotation at runtime to the PDF document. + +{% tabs %} +{% highlight C# %} + +//Adding ink annotation at runtime to the PDF document. +private void AddAnnotation() +{ + //Get the instance of the loadedDocument from the PdfViewerControl. + PdfLoadedDocument loadedDocument = pdfViewer.LoadedDocument; + + //Specify the ink points + List inkPoints = new List { 40, 300, 60, 100, 40, 50, 40, 300 }; + //Specify the bounds of an annotation + RectangleF rectangle = new RectangleF(0, 0, 300, 400); + //Create a new ink annotation + PdfInkAnnotation inkAnnotation = new PdfInkAnnotation(rectangle, inkPoints); + + //Add the ink annotation to the desired page of the PdfLoadedDocument property instance. + loadedDocument.Pages[0].Annotations.Add(inkAnnotation); +} + +{% endhighlight %} +{% highlight VB %} + +'Adding ink annotation at runtime to the PDF document. +private void AddAnnotation() +{ + 'Get the instance of the loadedDocument from the PdfViewerControl. + Dim loadedDocument As PdfLoadedDocument = pdfViewer.LoadedDocument + + 'Specify the ink points + Dim inkPoints As List(Of Single) = New List(Of Single) From {40, 300, 60, 100, 40, 50, 40, 300} + 'Specify the bounds of an annotation + Dim rectangle As RectangleF = New RectangleF(0, 0, 300, 400) + 'Create a new ink annotation + Dim inkAnnotation As PdfInkAnnotation = New PdfInkAnnotation(rectangle, inkPoints) + + 'Add the ink annotation to the desired page of the PdfLoadedDocument property instance. + loadedDocument.Pages[0].Annotations.Add(inkAnnotation) +} +{% endhighlight %} +{% endtabs %} ## Select an annotation From fec0e90501a6993f4148ff9b0a5bcf5d8c7178ec Mon Sep 17 00:00:00 2001 From: Krithika Date: Fri, 19 Jul 2024 14:07:08 +0530 Subject: [PATCH 2/4] 883474 Need to include adding annotation topic under programmatic support --- ...rking-with-Annotations-Programmatically.md | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md b/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md index 83bcbe9add..21aaa1340d 100644 --- a/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md +++ b/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md @@ -10,7 +10,7 @@ documentation: ug # Working with annotations programmatically ## Add an annotation -PDF Viewer allows the users to add the annotation programmatically without user interaction. We can add the annotation to the PDF document with the help of the [PdfViewerControl’s loadedDocument](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_LoadedDocument) property from the code behind. +PDF Viewer allows users to add annotations programmatically without user interaction. Annotations can be added to the PDF document using the [PdfViewerControl’s loadedDocument](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_LoadedDocument) property from the code behind. The following code snippet explains how to add an ink annotation at runtime to the PDF document. @@ -51,7 +51,7 @@ private void AddAnnotation() Dim inkAnnotation As PdfInkAnnotation = New PdfInkAnnotation(rectangle, inkPoints) 'Add the ink annotation to the desired page of the PdfLoadedDocument property instance. - loadedDocument.Pages[0].Annotations.Add(inkAnnotation) + loadedDocument.Pages(0).Annotations.Add(inkAnnotation) } {% endhighlight %} {% endtabs %} @@ -201,7 +201,9 @@ private void PdfViewer_DocumentLoaded(object sender, EventArgs args) {% endtabs %} ## Modify an annotation +PDF Viewer allows users to modify annotations programmatically without user interaction with the below ways. +### Modify an annotation using annotation changed event settings Annotation’s properties can be modified programmatically through `Settings` in respective annotation changed event. The following code snippet explains how to modify the selected ink annotation’s properties. Similarly, we can implement for all other annotations. @@ -224,6 +226,48 @@ private void PdfViewer_InkAnnotationChanged(object sender, InkAnnotationChangedE {% endhighlight %} {% endtabs %} +### Modify an annotation using loadedDocument + +Annotations can be modified to the PDF document using the [PdfViewerControl’s loadedDocument](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_LoadedDocument) property from the code behind. + +The following code snippet explains how to modify an ink annotation at runtime to the PDF document. + +{% tabs %} +{% highlight C# %} + +//Modify ink annotation at runtime to the PDF document. +private void ModifyAnnotation() +{ + //Get the instance of the loadedDocument from the PdfViewerControl. + PdfLoadedDocument loadedDocument = pdfViewer.LoadedDocument; + //Check whether the annotation in PdfInkAnnotation + if(loadedDocument.Pages[0].Annotations[0] is PdfInkAnnotation) + { + PdfInkAnnotation inkAnnotation = loadedDocument.Pages[0].Annotations[0] as PdfInkAnnotation; + //Modify the color of the ink annotation + inkAnnotation.Color = new PdfColor(System.Drawing.Color.Blue); + } +} + +{% endhighlight %} +{% highlight VB %} + +'Modify ink annotation at runtime to the PDF document. +private void ModifyAnnotation() +{ + 'Get the instance of the loadedDocument from the PdfViewerControl. + Dim loadedDocument As PdfLoadedDocument = pdfViewer.LoadedDocument + Dim inkAnnotation As PdfInkAnnotation = Nothing + 'Check whether the annotation in PdfInkAnnotation + If TypeOf loadedDocument.Pages(0).Annotations(1) Is PdfInkAnnotation Then + inkAnnotation = TryCast(loadedDocument.Pages(0).Annotations(1), PdfInkAnnotation) + 'Modify the color of the ink annotation + inkAnnotation.Color = New PdfColor(System.Drawing.Color.Blue) + End If +} +{% endhighlight %} +{% endtabs %} + ## Hide an annotation PDF Viewer allows the user to hide the annotation programmatically without user interaction. This functionality returns true if any annotation is found and hidden, otherwise it returns false. The annotation [Name](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.AnnotationChangedEventArgs.html#Syncfusion_Windows_PdfViewer_AnnotationChangedEventArgs_Name) property is used to identify the annotation. Refer this [UG link](https://help.syncfusion.com/wpf/pdf-viewer/working-with-annotations/select-and-modify-annotations#how-to-get-and-set-name-of-an-annotation) to get and set an annotation Name property. From 91996c15932a41844ce28d016c3f9befddb5d6bd Mon Sep 17 00:00:00 2001 From: Krithika Date: Fri, 19 Jul 2024 15:22:33 +0530 Subject: [PATCH 3/4] 883474 Need to include adding annotation topic under programmatic support --- .../Working-with-Annotations-Programmatically.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md b/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md index 21aaa1340d..8b3c87e9fe 100644 --- a/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md +++ b/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md @@ -259,8 +259,8 @@ private void ModifyAnnotation() Dim loadedDocument As PdfLoadedDocument = pdfViewer.LoadedDocument Dim inkAnnotation As PdfInkAnnotation = Nothing 'Check whether the annotation in PdfInkAnnotation - If TypeOf loadedDocument.Pages(0).Annotations(1) Is PdfInkAnnotation Then - inkAnnotation = TryCast(loadedDocument.Pages(0).Annotations(1), PdfInkAnnotation) + If TypeOf loadedDocument.Pages(0).Annotations(0) Is PdfInkAnnotation Then + inkAnnotation = TryCast(loadedDocument.Pages(0).Annotations(0), PdfInkAnnotation) 'Modify the color of the ink annotation inkAnnotation.Color = New PdfColor(System.Drawing.Color.Blue) End If From 880a4fbffae322f66702ea0499cdc08ff2dc8d2f Mon Sep 17 00:00:00 2001 From: Krithika Date: Fri, 19 Jul 2024 18:46:58 +0530 Subject: [PATCH 4/4] 883474 Need to include adding annotation topic under programmatic support --- ...orking-with-Annotations-Programmatically.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md b/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md index 8b3c87e9fe..0cff613932 100644 --- a/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md +++ b/wpf/Pdf-Viewer/Working-with-Annotations/Working-with-Annotations-Programmatically.md @@ -10,7 +10,7 @@ documentation: ug # Working with annotations programmatically ## Add an annotation -PDF Viewer allows users to add annotations programmatically without user interaction. Annotations can be added to the PDF document using the [PdfViewerControl’s loadedDocument](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_LoadedDocument) property from the code behind. +The PDF Viewer allows users to add annotations programmatically without user interaction. Annotations can be added to the PDF document using the [PdfViewerControl’s loadedDocument](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_LoadedDocument) property in the code behind. The following code snippet explains how to add an ink annotation at runtime to the PDF document. @@ -201,7 +201,7 @@ private void PdfViewer_DocumentLoaded(object sender, EventArgs args) {% endtabs %} ## Modify an annotation -PDF Viewer allows users to modify annotations programmatically without user interaction with the below ways. +The PDF Viewer allows users to modify annotations programmatically without user interaction in the following ways. ### Modify an annotation using annotation changed event settings Annotation’s properties can be modified programmatically through `Settings` in respective annotation changed event. @@ -228,19 +228,19 @@ private void PdfViewer_InkAnnotationChanged(object sender, InkAnnotationChangedE ### Modify an annotation using loadedDocument -Annotations can be modified to the PDF document using the [PdfViewerControl’s loadedDocument](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_LoadedDocument) property from the code behind. +Annotations can be modified in the PDF document using the [PdfViewerControl’s loadedDocument](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_LoadedDocument) property in the code behind. -The following code snippet explains how to modify an ink annotation at runtime to the PDF document. +The following code snippet demonstrates how to modify an ink annotation at runtime. {% tabs %} {% highlight C# %} -//Modify ink annotation at runtime to the PDF document. +//Modify the ink annotation in the PDF Viewer runtime. private void ModifyAnnotation() { //Get the instance of the loadedDocument from the PdfViewerControl. PdfLoadedDocument loadedDocument = pdfViewer.LoadedDocument; - //Check whether the annotation in PdfInkAnnotation + //Check whether the annotation is PdfInkAnnotation. if(loadedDocument.Pages[0].Annotations[0] is PdfInkAnnotation) { PdfInkAnnotation inkAnnotation = loadedDocument.Pages[0].Annotations[0] as PdfInkAnnotation; @@ -252,16 +252,16 @@ private void ModifyAnnotation() {% endhighlight %} {% highlight VB %} -'Modify ink annotation at runtime to the PDF document. +'Modify the ink annotation in the PDF Viewer runtime. private void ModifyAnnotation() { 'Get the instance of the loadedDocument from the PdfViewerControl. Dim loadedDocument As PdfLoadedDocument = pdfViewer.LoadedDocument Dim inkAnnotation As PdfInkAnnotation = Nothing - 'Check whether the annotation in PdfInkAnnotation + 'Check whether the annotation is PdfInkAnnotation. If TypeOf loadedDocument.Pages(0).Annotations(0) Is PdfInkAnnotation Then inkAnnotation = TryCast(loadedDocument.Pages(0).Annotations(0), PdfInkAnnotation) - 'Modify the color of the ink annotation + 'Modify the color of the ink annotation. inkAnnotation.Color = New PdfColor(System.Drawing.Color.Blue) End If }