Get PDF document’s data from Blazor SfPdfViewer Component

21 Jun 20231 minute to read

You can get the loaded PDF document’s data from the SfPdfViewer component using the GetDocumentAsync() method of SfPdfViewer.

The following code example shows how to get the loaded/edited document data and re-load the document.

@using Syncfusion.Blazor.SfPdfViewer
@using Syncfusion.Blazor.Buttons

<SfButton @onclick="retrieve">Retrieve Document</SfButton>

<SfButton @onclick="load">ReloadRetrievedDocument</SfButton>

<SfPdfViewer2 @ref="@viewer"

    SfPdfViewer2 viewer;
    private string DocumentPath { get; set; } = "wwwroot/Data/PDF_Succinctly.pdf";

    byte[]? save;

    public async void retrieve()
        //Gets the loaded PDF document
        save = await viewer.GetDocumentAsync();

    public async void load()
        //Converts the byte array into base64 string.
        string base64String = Convert.ToBase64String(save);
        //Loads the PDF document from the specified base64 string.
        await viewer.LoadAsync("data:application/pdf;base64," + base64String, null);

View sample in GitHub.

See also