Create, edit, or remove PDF annotations in UWP
After Nutrient UWP SDK loads annotations from a PDF, you can access them through the Document
API.
-
The API returns a
List
ofIAnnotation
objects. -
Each
IAnnotation
provides access to shared properties and methods, including:
Understanding the annotation bounding box
The BoundingBox
defines the annotation’s location and size on the page. It’s represented by a Rect
with:
-
X
andY
describing the top-left coordinate of the annotation on the page. -
Width
andHeight
describing the size of the annotation.
Coordinate system
Nutrient UWP SDK and Nutrient Web SDK use the Instant JSON coordinate system:
-
The origin of the page, “0,0,” is at the top left.
-
The Y axis value increases as you move down the page.
To convert between the coordinate system above and the PDF coordinate system (where origin, “0,0,” is at the bottom left, with the Y axis value increasing as you move up the page), refer to the conversion utility methods guide.
Working with specific annotation types
Use the AnnotationType
property to cast to a specific annotation type to work with its APIs:
if (annotation.AnnotationType == AnnotationType.Ink) { var ink = annotation as AnnotationType.Ink; return ink.IsSignature; }
Creating an annotation
To create an annotation on a page:
-
Instantiate the desired annotation type, as demonstrated in the code snippet below:
var textAnnot = new Text { Contents = "A new text annotation", HorizontalAlign = HorizontalAlign.Right, VerticalAlign = VerticalAlign.Center, BoundingBox = new Rect(10, 10, 300, 300), FontSize = 48, Bold = true, Italic = true, FontColor = Colors.Cyan };
-
Add the annotation to a page, as demonstrated in the code snippet below:
var createdTextAnnotation = await pdfView.Document.CreateAnnotationAsync(textAnnot);
-
Once added, the annotation will have a unique
Id
.
Updating an annotation
To update an existing annotation, use the code snippet below:
createdTextAnnotation.VerticalAlign = VerticalAlign.Top; createdTextAnnotation.Opacity = 0.5f; await pdfView.Document.UpdateAnnotationAsync(createdTextAnnotation);
Deleting an annotation
To delete an annotation, use the annotation’s Id
to remove it, as demonstrated in the code snippet below:
await pdfView.Document.DeleteAnnotationAsync(createdTextAnnotation.Id);