Unload the PDF document programmatically

23 Oct 20251 minute to read

The Syncfusion® ASP.NET MVC PDF Viewer exposes the unload() method to remove the currently displayed document, release associated resources, and reset the viewer UI. Use this approach when switching between files or clearing sensitive content after it has been reviewed.

Follow these steps to unload a PDF document programmatically:

Step 1: Create a PDF Viewer sample by following the ASP.NET MVC getting started guide so the required scripts, styles, and controller endpoints are configured.

Step 2: Add the following markup and script to call unload() when the button is clicked. Place the script within the Razor page after the viewer element so the instance is available.

<button type="button" onclick="unload()">Unload Document</button>

<div id="e-pv-e-sign-pdfViewer-div">
    @Html.EJS().PdfViewer("pdfviewer").DocumentPath("https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf").Render()
</div>

<script>
    // Unload the PDF document.
    function unload() {
        var viewer = document.getElementById('pdfviewer').ej2_instances[0];
        viewer.unload();
    }
</script>
<button type="button" onclick="unload()">Unload Document</button>

<div id="e-pv-e-sign-pdfViewer-div">
    @Html.EJS().PdfViewer("pdfviewer").ServiceUrl(VirtualPathUtility.ToAbsolute("~/PdfViewer/")).DocumentPath("https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf").Render()
</div>

<script>
    // Unload the PDF document.
    function unload() {
        var viewer = document.getElementById('pdfviewer').ej2_instances[0];
        viewer.unload();
    }
</script>

After calling unload(), the viewer removes the document and toolbar state until a new file is loaded. Apply the same pattern in both standalone and server-backed configurations to ensure cached data is cleared before loading a different PDF.

how to unload the PDF document programmatically