Syncfusion AI Assistant

How can I help you?

Annotation Collection in .NET MAUI PDF Viewer (SfPdfViewer)

7 Mar 20262 minutes to read

The existing annotations in a PDF document can be accessed using the Annotations property of the SfPdfViewer. This read only property will have the annotation collection information as soon as the document is loaded into the PDF Viewer. The following example explains how to use the property to obtain information about a square annotation that is the first on a specific document.

public void WireDocumentLoadedEvent()
{
    // Wire the document loaded event of the [SfPdfViewer](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html) to occur when a PDF document is loaded.
    PdfViewer.DocumentLoaded += OnDocumentLoaded;
}

private void OnDocumentLoaded(object sender, EventArgs e)
{
    if (sender is SfPdfViewer pdfViewer)
    {
        // Obtain the annotation collection.
        ReadOnlyObservableCollection<Annotation> annotations = pdfViewer.Annotations;
        
        if (annotations.Count > 0)
        {
            // Type cast the annotation to get the annotation-specific properties.
            if (annotations[0] is SquareAnnotation squareAnnotation)
            {
                RectF bounds = squareAnnotation.Bounds;
                Color color = squareAnnotation.Color;
            }
        }
    }
}

AnnotationsLoaded event

The AnnotationsLoaded event occurs after all annotations in the PDF have finished loading, either when the document is opened or when annotations are imported. You can use this event to perform actions once annotations are fully available in the viewer.
The following example explains how to wire and handle the event.

void WireAnnotationsLoadedEvent() 
{ 
    // Wire the annotations loaded event of [SfPdfViewer](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.PdfViewer.SfPdfViewer.html).
    pdfViewer.AnnotationsLoaded += OnAnnotationsLoaded; 
} 

private void OnAnnotationsLoaded(object? sender, EventArgs e) 
{ 
    Debug.WriteLine("All annotations have been loaded."); 
}

See Also