Unload the PDF document from Viewer in Blazor SfPdfViewer Component
17 Jul 20261 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. The DocumentUnloaded event fires when the document is closed.
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 {
private SfPdfViewer2 Viewer;
private async Task OnClick(MouseEventArgs args)
{
await Viewer.UnloadAsync();
}
private string DocumentPath { get; set; } = "wwwroot/data/PDF_Succinctly.pdf";
}