Load documents in EJ2 JavaScript Pdfviewer control

13 Sep 20231 minute to read

The PDF Viewer library allows to switch or load the PDF documents dynamically after the initial load operation. To achieve this, load the PDF document as a base64 string or file name in PDF Viewer control using the Load() method dynamically.

The following steps are used to load the PDF document dynamically.

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

Step 2: Use the following code snippet to load PDF document using base64 string.

<button id='load1'>LoadDocumentFromBase64</button>
// Load PDF document from Base64 string
document.getElementById('load1').addEventListener('click', () => {
  viewer.load(
    'data:application/pdf;base64,'+ AddBase64String, null);
}

Step 3: Use the following code snippet to load PDF document using document name.

<button id='load2'>LoadDocument</button>
// Load PDF document using file name
document.getElementById('load2').addEventListener('click', () => {
  viewer.load('https://cdn.syncfusion.com/content/pdf/pdf-succinctly.pdf', null);
});

Find the sample, how to load PDF documents dynamically