Install

Grab the package on NPM with:

npm install mupdf-webviewer

Trial License

A trial license key is required to use MuPDF WebViewer. For local development and testing, this license key will also operate for the localhost domain. Visit MuPDF WebViewer to obtain your trial license.

Copy the library assets

The library folder for MuPDF WebViewer is required to be copied to a library path of your choosing.

cp -r node_modules/mupdf-webviewer/lib/* {YOUR_LIBRARY_PATH}/

For example in a React environment you probably want to just make this available in the public folder as follows:

cp -r ./node_modules/mupdf-webviewer/lib ./public

Prepare your DOM

Ensure that your HTML page where you want to use MuPDF WebViewer has a dedicated DOM node available with the id you require, e.g.

<div id="viewer"></div>

Initialization

Once ready you should initialize with initMuPDFWebViewer().

Example:

import { initMuPDFWebViewer } from 'mupdf-webviewer'

initMuPDFWebViewer('#viewer', 'sample.pdf', {
  libraryPath: 'YOUR_LIBRARY_PATH',
  licenseKey: 'YOUR_LICENSE_KEY',
})
  .then(mupdf => {
    /* API */
    mupdf.toast.show({ type: 'success', content: 'Opened' });
  })
  .catch(err => {
    /* Error handling */
  });

Running

You should be able to run on your local machine’s browser. When deploying to the web don’t forget that your license key is specific to the domain you registered the key against.