Unload the document in Pdf Viewer

10 Jan 20251 minute to read

The WPF PDF Viewer also allows a user to Unload the PDF document using Unload() API of the PdfViewerControl and PdfDocumentView classes. A user can dispose the PDF document by passing the Boolean parameter as ‘true’ to the Unload(Boolean) API. The below code illustrates how to dispose the PDF document programmatically.

private void UnloadButton_Click(object sender, RoutedEventArgs e)
{
      //Unload the PDF document
      pdfviewer.Unload(true);
}
Private Sub UnloadButton_Click(sender As Object, e As RoutedEventArgs)
     'Unload the PDF document
    pdfviewer.Unload(true)
End Sub

NOTE

In PdfViewerControl, it is recommended not to unload the PDF document externally when loading a new PDF document, as the control internally handles the unloading process.