Initialization

The MuPDF WebViewer API can only be accessed after initializing with initMuPDFWebViewer(). This should return a mupdfwv.MuPDFWebViewer object to your code base or an error if there is any problem with the initialization.

initMuPDFWebViewer

initMuPDFWebViewer(selector: string, docURL: string, options?: mupdfwv.initViewerOptions): Promise<mupdfwv.MuPDFWebViewer>()

  • Arguments:
    • selector – A string which targets the dedicated <div> with the expected id.
    • docURL – The URL of the document you wish to display.
    • options – An object containing the libraryPath and licenseKey definitions.
  • Returns: Promise object as Promise<mupdfwv.MuPDFWebViewer>.
import { initMuPDFWebViewer } from 'mupdf-webviewer'

initMuPDFWebViewer('#viewer', 'sample.pdf', {
  libraryPath: 'lib',
  licenseKey: 'YOUR_LICENSE_KEY',
})
  .then(mupdf => {
    /* Returns a mupdfwv.MuPDFWebViewer object for our API access */
    mupdf.toast.show({ type: 'success', content: 'Opened' });
  })
  .catch(err => {
    /* Error handling */
    console.log(err);
  });

mupdfwv.MuPDFWebViewer

The mupdfwv.MuPDFWebViewer object instance contains six sub-object instances as follows:

document instance

The PDF document instance.


viewer instance

The viewer user interface used for interaction.


annotation instance

An interface into the document’s annotations.


text instance

The interface for the document text.


watermark instance

An interface to manage document watermarks.


toast instance

An object used to display messages.

Events

How to listen to events in the MuPDF WebViewer.

References

A glossary of object references.