Import annotations as objects in Blazor SfPdfViewer Component

17 Jul 20261 minute to read

The Blazor SfPdfViewer component supports importing annotations from an object previously exported by the component. To obtain such an annotation object, use the ExportAnnotationsAsObjectAsync() method. Only annotation objects exported by the SfPdfViewer component can be imported.

The following example shows how to export annotations as an object and import them back using the SfPdfViewer component.

@page "/"
@using Syncfusion.Blazor.SfPdfViewer

<button @onclick="ExportAnnotation">Export Annotations</button>
<button @onclick="ImportAnnotation">Import Annotations</button>

<SfPdfViewer2 @ref="PdfViewer"
              DocumentPath="@DocumentPath"
              Height="100%"
              Width="100%">
</SfPdfViewer2>

@code {
    private SfPdfViewer2 PdfViewer { get; set; }
    private string DocumentPath { get; set; } = "PDF_Succinctly.pdf";
    private object annotation;

    //Export the annotations as an object
    private async Task ExportAnnotation()
    {
        await PdfViewer.ExportAnnotation();
        annotation = await PdfViewer.ExportAnnotationsAsObjectAsync();
    }

    //Import the annotations that are exported as objects
    private async Task ImportAnnotation()
    {
        await PdfViewer.ImportAnnotation(annotation);
    }
}

View the sample on GitHub.

See also