Some test text!

menu
Where to find code snippets for WebViewer 5.0 or earlier?keyboard_arrow_down

Where can I find code snippets for WebViewer 5.0 or earlier?

With the release of WebViewer 6.0, code snippets of all the guides have been updated to include only v6.0+ and v5.1+. If you are still using WebViewer 5.0.x, you can use v5.1+ snippets with a few tweaks.

The biggest difference between WebViewer 5.1 and 5.0 is how it is instantiated. The promisified instantiation isn't available in 5.0 so you need to listen to the ready event instead. Also, objects and namespaces such as Annotations, Tools, CoreControls aren't attached to the instance object in 5.0 so you need to grab them from the iframe window.

// v5.1+
WebViewer({
  ...
}, document.getElementById('viewer'))
  .then(instance => {
    const {
      docViewer,
      annotManager,
      Tools,
      Annotations,
      CoreControls,
      PartRetrievers,
      Actions,
      PDFNet,
    } = instance;

    // call instance APIs here
  });
// v5.0
const viewerElement = document.getElementById('viewer');
const viewer = new PDFTron.WebViewer({
  ...
}, viewerElement);

viewer.addEventListener('ready', () => {
  const instance = viewer.getInstance();
  
  const docViewer = instance.docViewer;
  const annotManager = docViewer.getAnnotationManager();
  const {
    Tools,
    Annotations,
    CoreControls,
    PartRetrievers,
    Actions,
    PDFNet,
  } = document.querySelector('iframe').contentWindow;
  
  // call instance APIs here
});

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our upcoming webinar to find out about built-in, full-functioning document capabilities directly in Salesforce.

Save your seat
close