Annotations
Add, list and remove PDF annotations from code in a .NET MAUI app and refresh the PdfView.
License module
Creating and changing annotations needs the annotations module (Indie tier and above). Listing
annotations works without a key.
PdfView has no annotation tools (1.1 included). Annotations are added from code through view.Document;
call ReloadAsync() afterwards so the view shows them. Coordinates are PDF points with the origin
at the bottom-left of the page.
var doc = view.Document!;
var page = view.CurrentPage;
doc.AddAnnotation(page, "Highlight", "#FFD400", 1.0, "", 72, 700, 300, 716);
doc.AddAnnotation(page, "Text", "#2563EB", 1.0, "Please confirm this date", 320, 700, 340, 720);
doc.AddLine(page, "Arrow", "#DC2626", 1.0, 2.0, 100, 500, 250, 560);
doc.AddInk(page, "#1D4ED8", 2.0, 1.0, "100,400;120,410;140,405;160,420");
await view.ReloadAsync();List and remove
using System.Text.Json.Nodes;
foreach (var a in JsonNode.Parse(doc.AnnotationsJson(page))!.AsArray())
{
if (a!["kind"]!.GetValue<string>() == "Highlight")
doc.RemoveAnnotation(page, a["num"]!.GetValue<uint>(), a["gen"]!.GetValue<ushort>());
}
await view.ReloadAsync();Save the result
var path = Path.Combine(FileSystem.AppDataDirectory, "annotated.pdf");
doc.Save(path);XFDF exchange, image stamps, measurements, flattening and file attachments are covered in the
.NET annotations guide. For hand-drawn annotation tools today,
embed the web viewer in a WebView.