Unload document in JavaScript PDF Viewer

13 Feb 20261 minute to read

The PDF Viewer provides the unload() method to remove the currently loaded PDF from the viewer instance. Use this API to free memory or reset the viewer when navigating between documents or closing the viewer.

The following steps are used to unload the PDF document programmatically.

Step 1: Follow the steps provided in the link to create a simple PDF Viewer sample.

Step 2: Add the following code snippet to perform the unload operation.

  <button id="unload">Unload Document</button>
document.getElementById('unload').addEventListener('click', () => {
   // Unload the document.
  viewer.unload();
});

Find the Sample, how to unload the PDF document programmatically