Some test text!

Document loading

In this document
chevron_rightLoading WebViewer without a document
chevron_rightLoading multiple documents with loadDocument

The easiest way to load a document in WebViewer is by specifying the initialDoc option but what if you want to do something a bit different? For example loading multiple documents in sequence or preloading WebViewer without a document and then loading the document later.

linkLoading WebViewer without a document

If you want to instantiate the viewer without loading any document (maybe you're getting the document URL asynchronously) then you can simply not set the initialDoc option. The viewer UI will be loaded and you can call the loadDocument function when you're ready to load a document.

linkLoading multiple documents with loadDocument

If you want to load multiple documents in your app you'll want to reuse WebViewer. This is better than removing the old iframe and creating a new instance of WebViewer because some browsers have trouble with this and may leak memory.

To reuse WebViewer just keep a reference to your WebViewer instance and call loadDocument with the new document URL.

var myWebViewer = new PDFTron.WebViewer({
  initialDoc: 'mysite.com/myfirstdocument.pdf',
  documentId: 'id1'
}, viewerElement);

// later on
loadDocumentButton.on('click', function() {
  myWebViewer.loadDocument('mysite.com/myOtherDocument.pdf', { documentId: 'id2' });
});