Unload the PDF document from Viewer in Blazor SfPdfViewer Component

14 Oct 20251 minute to read

The SfPdfViewer component automatically unloads the current PDF and releases its resources when the component is disposed. When a different PDF is loaded, the resources used by the previously loaded file are also released.

To unload a PDF and release its resources programmatically, call the UnloadAsync 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