Some test text!

Custom annotation appearancekeyboard_arrow_down

Create custom annotations in Xamarin

It's possible to modify an annotation's appearance directly using PDFNet.

The sample code below demonstrates how to replace an annotation's appearance with a custom image.

public void SetCustomImage(Annot annot, PDFDoc doc, string imagePath)
    // Initialize a new ElementWriter and ElementBuilder
    ElementWriter writer = new ElementWriter();
    ElementBuilder builder = new ElementBuilder();

    writer.Begin(doc.GetSDFDoc(), true);

    // Initialize the new image
    Image image = Image.Create(doc.GetSDFDoc(), imagePath);
    int w = image.GetImageWidth();
    int h = image.GetImageHeight();

    // Initialize a new image element
    Element element = builder.CreateImage(image, 0, 0, w, h);

    // Write the element

    // Get the bounding box of the new element
    Rect bbox = new Rect();

    // Configure the appearance stream that will be written to the annotation
    Obj new_appearance_stream = writer.End();

    // Set the bounding box to be the rect of the new element

    // Overwrite the annotation's appearance with the new appearance stream

In addition to images, an annotation's appearance can be created using (nearly) everything the PDF specification allows, including vector content and text. For an example of how to create PDF vector and text content, see the ElementBuilder sample.

If you call RefreshAppearance after modifying the appearance of a `PTAnnot`, then the annotation's default appearance will be restored and any changes you have made will be lost.

Get the answers you need: Support


Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more