Preloading and sharing WebViewer instance

190 views
Skip to first unread message

Matt Parizeau

unread,
Dec 21, 2016, 2:17:15 PM12/21/16
to PDFTron WebViewer
Q:

Is it possible to preload WebViewer in the background to speed up the time it takes to load a document the first time? I also want to load multiple documents which might have a different documentId and server URL.

A:

In the WebViewer showcase you can see an example of preloading the viewer so that it's ready immediately if you choose to open a PDF file. To do this you can initialize WebViewer like normal but add a "hidden" class to the viewerElement that WebViewer is being initialized with. The hidden class should look like this:

.hidden {
  width: 0 !important;
  height: 0 !important;
}

The reason you do this instead of display:none is because there is an issue in Firefox with using display: none.

When you want to show WebViewer you remove the hidden class on the element and then call myWebViewer.loadDocument to load a particular document.

Before you call loadDocument you can set properties that are equivalent to the WebViewer intitialization options. For example:

myWebViewer.getInstance().serverUrl = myServerUrl;
myWebViewer.getInstance().docId = myDocId;
myWebViewer.setAnnotationUser(myUser);
myWebViewer.setReadOnly(isReadOnly);

For the "custom" property you could instead set it on the WebViewer instance. For example:

myWebViewer.getInstance().customData = customData;

Then in your config file you can access it from:

readerControl.customData
Reply all
Reply to author
Forward
0 new messages