Unload the PDF document from Viewer in Blazor SfPdfViewer Component

4 Jul 20241 minute to read

The SfPdfViewer component will automatically unload and clear the resources occupied by the PDF document when the control is disposed. Also, when loading another PDF file, the resources occupied by previous loaded file in viewer will be automatically unloaded and cleared.

If you want to unload and clear the resources occupied by the PDF file programmatically, invoke the Unload() method as shown below.

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

<SfButton @onclick="OnClick">Unload Document</SfButton>

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

@code {
    SfPdfViewer2 Viewer;

    public async void OnClick(MouseEventArgs args)
    {
        await Viewer.UnloadAsync();
    }

    public string DocumentPath { get; set; } = "wwwroot/data/PDF_Succinctly.pdf";
}

View sample in GitHub

See also