chevron_right
close
chevron_right

Get Started

chevron_right

Learn more

chevron_right

Open a document

chevron_right

Viewer

chevron_right

UI Customization

chevron_right

Annotations

chevron_right

Collaboration

chevron_right

Forms

chevron_right

Signature

chevron_right

Measurement

Framework compatibility for PDF.js Express

PDF.js Express Web Viewer is compatible with any JavaScript framework because all it needs is a DOM element to place the document viewing component.

  • Angular
  • Cordova
  • Electron
  • React
  • Svelte
  • Vue

Integrate into other frameworks

Integrating PDF.js Express into a framework (any framework) is broken down to three steps:

  1. Importing
  2. Instantiating
  3. Calling APIs

Import

To import PDF.js Express, you can either import is as a script tag:

<script src='PATH_TO_EXPRESS_WEBVIEWER/lib/webviewer.min.js'></script>

or as a module.

Instantiate

The PDF.js Express Web Viewer constructor takes two arguments: options and a DOM element. Regardless of the framework, you must pass a DOM element which will contain PDF.js Express' iframe.

Given the instantiation code:

WebViewer({
  path: 'PATH_TO_EXPRESS_WEBVIEWER/lib',
  licenseKey: 'Insert commercial license key here after purchase',
  initialDoc: 'path/to/doc.pdf'
}, HTML_DIV_ELEMENT);

you can reference a DOM element based on your framework:

// Vanilla JS
WebViewer({ ... }, document.getElementById('viewer'));
// React
WebViewer({ ... }, this.viewerRef.current);
// Angular
WebViewer({ ... }, this.viewer.nativeElement);

Call APIs

Before calling APIs, you should wait for appropriate events to be fired from PDF.js Express.

// Vanilla JS
WebViewer(...)
  .then(function(instance) {
    onReady();

    var docViewer = instance.docViewer;
    docViewer.on('documentLoaded', onDocumentLoaded);
  });
// React and Angular
WebViewer(...)
  .then(function(instance) {
    this.onReady(instance);

    var docViewer = instance.docViewer;
    docViewer.on('documentLoaded', this.onDocumentLoaded.bind(this, instance));
  }.bind(this));

and call APIs from viewer instance:

// Vanilla JS
var onReady = function(instance) {
  // Executed when the viewer is ready
  // NOTE: Document is not loaded yet
  instance.enableFilePicker();
};
var onDocumentLoaded = function(instance) {
  // Executed when the document is loaded
  // NOTE: Document is not rendered yet
  instance.getPageCount();
}
// React and Angular
onReady(instance) {
  // Executed when the viewer is ready
  // NOTE: Document is not loaded yet
  instance.enableFilePicker();
}
onDocumentLoaded(instance) {
  // Executed when the document is loaded
  // NOTE: Document is not rendered yet
  instance.getPageCount();
}