How do I create an image annotation?
To programmatically create an image annotation from a file, you first need to create an attachment in the document using a buffer and the content type. That will give you an ID for the attachment. Then you can construct an Image
annotation and set the ImageAttachmentId
and ContentType
properties:
var buffer = await FileIO.ReadBufferAsync(file);
// Create an annotation attachment for the image in the document and get its ID.var attachmentId = await PDFView.Controller.GetPdfDocument().CreateAttachmentAsync(buffer, file.ContentType);
// Next, define the bounding box of the annotation on the page.var boundingBox = new Rect(100, 100, 100, 100);
// Create the annotation and set the image attachment ID and the content type.var annotation = new Image{ BoundingBox = boundingBox, Description = "Logo", ImageAttachmentId = attachmentId, ContentType = file.ContentType, PageIndex = 0};
// Add the annotation to the document.annotation = await PDFView.Document.CreateAnnotationAsync(annotation) as Image;
For more information, refer to the example code in the Catalog.