Skip to main content

Initialization

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

initMuPDFWebViewer

export function initMuPDFWebViewer(
  selector: string,
  docURL: string,
  options?: {
    licenseKey?: string;
    libraryPath?: string;
    filename?: string;
    standalone?: boolean;
    withoutLoader?: boolean;
    author?: string;
  }
): Promise<MuPDFWebViewer>;

Parameters

selector
string
required
A CSS selector used to find the DOM element that will host the viewer. Supports any selector supported by querySelector.
docURL
string
required
The URL of the document you wish to display.
options
object
Optional initialization options.

Returns

result
Promise<MuPDFWebViewer>
required
A Promise that resolves to a MuPDFWebViewer instance.
Example
import { initMuPDFWebViewer } from 'mupdf-webviewer'

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

MuPDFWebViewer

The MuPDFWebViewer instance exposes object instances and helper APIs as follows:

document instance

The PDF document instance.

viewer instance

The viewer user interface used for interaction.

watermark instance

An interface to manage document watermarks.

capture instance

The interface for capturing images from a document.

text instance

The interface for the document text.

annotation instance

An interface for managing document annotations.

redaction instance

An interface for managing document redactions.

toast instance

An object used to display messages.

Events

How to listen to events in the MuPDF WebViewer.

References

A glossary of object references.