> ## Documentation Index
> Fetch the complete documentation index at: https://webviewer-docs.mupdf.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction

> The MuPDF WebViewer API

## Initialization

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

### initMuPDFWebViewer

```typescript theme={null}
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](https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Selectors) 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.

**options properties**

**options.licenseKey** `string`

The [license key](https://webviewer.mupdf.com/pricing) to use.

**options.libraryPath** `string`

Library path for library assets. See [Optionally set the library path](https://webviewer-docs.mupdf.com/getting-started.md#optionally-set-the-library-path).

**options.filename** `string`

Filename for the PDF.

**options.standalone** `boolean`

Whether to run in standalone mode.

**options.withoutLoader** `boolean`

Whether to hide the document loader.

**options.author** `string`

Default author used in annotation metadata.

#### Returns

**result** `Promise\<MuPDFWebViewer\>` *required*

A Promise that resolves to a `MuPDFWebViewer` instance.

**Example**

```javascript theme={null}
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.

* [Document API](https://webviewer-docs.mupdf.com/api-reference/document/index.md)
  * [`document`](https://webviewer-docs.mupdf.com/api-reference/document/index#document)
    * [`document.open()`](https://webviewer-docs.mupdf.com/api-reference/document/index#open)
    * [`document.download()`](https://webviewer-docs.mupdf.com/api-reference/document/index#download)
    * [`document.getPages()`](https://webviewer-docs.mupdf.com/api-reference/document/index#getpages)
    * [`document.getPageCount()`](https://webviewer-docs.mupdf.com/api-reference/document/index#getpagecount)
    * [`document.close()`](https://webviewer-docs.mupdf.com/api-reference/document/index#close)
    * [`document.print()`](https://webviewer-docs.mupdf.com/api-reference/document/index#print)
    * [`document.rotatePage()`](https://webviewer-docs.mupdf.com/api-reference/document/index#rotatepage)
    * [`document.getText()`](https://webviewer-docs.mupdf.com/api-reference/document/index#gettext)
    * [`document.export()`](https://webviewer-docs.mupdf.com/api-reference/document/index#export)

***

### `viewer` instance

The viewer user interface used for interaction.

* [Viewer API](https://webviewer-docs.mupdf.com/api-reference/viewer/index.md)
  * [`viewer`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#viewer)
    * [`viewer.toggleDialog()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#toggledialog)
    * [`viewer.getScale()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#getscale)
    * [`viewer.setScale()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#setscale)
    * [`viewer.zoomIn()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#zoomin)
    * [`viewer.zoomOut()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#zoomout)
    * [`viewer.getCurrentPageIndex()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#getcurrentpageindex)
    * [`viewer.getRotation()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#getrotation)
    * [`viewer.setRotation()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#setrotation)
    * [`viewer.rotateClockwise()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#rotateclockwise)
    * [`viewer.rotateCounterClockwise()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#rotatecounterclockwise)
    * [`viewer.setViewMode()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#setviewmode)
    * [`viewer.fitTo()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#fitto)
    * [`viewer.scrollTo()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#scrollto)
    * [`viewer.scrollToNextPage()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#scrolltonextpage)
    * [`viewer.scrollToPreviousPage()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#scrolltopreviouspage)
    * [`viewer.selectAnnotationTool()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#selectannotationtool)
    * [`viewer.toggleAnnotationTool()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#toggleannotationtool)
    * [`viewer.openSideView()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#opensideview)
    * [`viewer.closeSideView()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#closesideview)
    * [`viewer.togglePanel()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#togglepanel)
    * [`viewer.highlight()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#highlight)
    * [`viewer.unhighlight()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#unhighlight)
    * [`viewer.searchText()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#searchtext)
    * [`viewer.setViewVisibility()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#setviewvisibility)
    * [`viewer.addButton()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#addbutton)
    * [`viewer.openContextMenu()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#opencontextmenu)
    * [`viewer.addContextMenu()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#addcontextmenu)
    * [`viewer.defineDocumentPanel()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#definedocumentpanel)
    * [`viewer.defineTextSelectionMenu()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#definetextselectionmenu)
    * [`viewer.defineAnnotSelectMenu()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#defineannotselectmenu)
    * [`viewer.defineRightClickAction()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#definerightclickaction)
    * [`viewer.setBackgroundColor()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#setbackgroundcolor)
    * [`viewer.setPageBorderColor()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#setpagebordercolor)
    * [`viewer.setColor()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#setcolor)
    * [`viewer.setTheme()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#settheme)
    * [`viewer.setLanguage()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#setlanguage)
    * [`viewer.getSize()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#getsize)
    * [`viewer.setLogo()`](https://webviewer-docs.mupdf.com/api-reference/viewer/index#setlogo)

***

### `watermark` instance

An interface to manage document watermarks.

* [Watermark API](https://webviewer-docs.mupdf.com/api-reference/watermark/index.md)
  * [`watermark`](https://webviewer-docs.mupdf.com/api-reference/watermark/index#watermark)
    * [`watermark.create()`](https://webviewer-docs.mupdf.com/api-reference/watermark/index#create)

***

### `capture` instance

The interface for capturing images from a document.

* [Capture API](https://webviewer-docs.mupdf.com/api-reference/capture/index.md)
  * [`capture`](https://webviewer-docs.mupdf.com/api-reference/capture/index#capture)
    * [`capture.selectAndExport()`](https://webviewer-docs.mupdf.com/api-reference/capture/index#selectandexport)

***

### `text` instance

The interface for the document text.

* [Text API](https://webviewer-docs.mupdf.com/api-reference/text/index.md)
  * [`text`](https://webviewer-docs.mupdf.com/api-reference/text/index#text)
    * [`text.search()`](https://webviewer-docs.mupdf.com/api-reference/text/index#search)
    * [`text.locateSource()`](https://webviewer-docs.mupdf.com/api-reference/text/index#locatesource)
    * [`text.getSelected()`](https://webviewer-docs.mupdf.com/api-reference/text/index#getselected)

***

### `annotation` instance

An interface for managing document annotations.

* [Annotation API](https://webviewer-docs.mupdf.com/api-reference/annotation/index.md)
  * [`annotation`](https://webviewer-docs.mupdf.com/api-reference/annotation/index#annotation)
    * [`annotation.remove()`](https://webviewer-docs.mupdf.com/api-reference/annotation/index#remove)
    * [`annotation.get()`](https://webviewer-docs.mupdf.com/api-reference/annotation/index#get)
    * [`annotation.add()`](https://webviewer-docs.mupdf.com/api-reference/annotation/index#add)
    * [`annotation.set()`](https://webviewer-docs.mupdf.com/api-reference/annotation/index#set)
    * [`annotation.undo()`](https://webviewer-docs.mupdf.com/api-reference/annotation/index#undo)
    * [`annotation.redo()`](https://webviewer-docs.mupdf.com/api-reference/annotation/index#redo)

***

### `redaction` instance

An interface for managing document redactions.

* [Redaction API](https://webviewer-docs.mupdf.com/api-reference/redaction/index.md)
  * [`redaction`](https://webviewer-docs.mupdf.com/api-reference/redaction/index#redaction)
    * [`redaction.get()`](https://webviewer-docs.mupdf.com/api-reference/redaction/index#get)
    * [`redaction.set()`](https://webviewer-docs.mupdf.com/api-reference/redaction/index#set)
    * [`redaction.add()`](https://webviewer-docs.mupdf.com/api-reference/redaction/index#add)
    * [`redaction.remove()`](https://webviewer-docs.mupdf.com/api-reference/redaction/index#remove)
    * [`redaction.apply()`](https://webviewer-docs.mupdf.com/api-reference/redaction/index#apply)
  * [`Redaction Types`](https://webviewer-docs.mupdf.com/api-reference/redaction/index#redaction-types)

***

### `toast` instance

An object used to display messages.

* [Toast API](https://webviewer-docs.mupdf.com/api-reference/toast/index.md)
  * [`toast`](https://webviewer-docs.mupdf.com/api-reference/toast/index#toast)
    * [`toast.show()`](https://webviewer-docs.mupdf.com/api-reference/toast/index#show)

## Events

How to listen to events in the **MuPDF WebViewer**.

* [Events API](https://webviewer-docs.mupdf.com/api-reference/events/index.md)

## References

A glossary of object references.

* [References](https://webviewer-docs.mupdf.com/api-reference/refs/index.md)
* [`webViewer.refs`](https://webviewer-docs.mupdf.com/api-reference/refs/index#webviewer-refs)
  * [`scroll`](https://webviewer-docs.mupdf.com/api-reference/refs/index#scroll)
  * [`fit`](https://webviewer-docs.mupdf.com/api-reference/refs/index#fit)
  * [`viewMode`](https://webviewer-docs.mupdf.com/api-reference/refs/index#viewmode)
  * [`degree`](https://webviewer-docs.mupdf.com/api-reference/refs/index#degree)
  * [`dialog`](https://webviewer-docs.mupdf.com/api-reference/refs/index#dialog)
  * [`panel`](https://webviewer-docs.mupdf.com/api-reference/refs/index#panel)
  * [`theme`](https://webviewer-docs.mupdf.com/api-reference/refs/index#theme)
  * [`language`](https://webviewer-docs.mupdf.com/api-reference/refs/index#language)
  * [`annotation`](https://webviewer-docs.mupdf.com/api-reference/refs/index#annotation)
  * [`visibility`](https://webviewer-docs.mupdf.com/api-reference/refs/index#visibility)
  * [`redaction`](https://webviewer-docs.mupdf.com/api-reference/refs/index#redaction)
  * [`text`](https://webviewer-docs.mupdf.com/api-reference/refs/index#text)
  * [`icon`](https://webviewer-docs.mupdf.com/api-reference/refs/index#icon)
  * [`event`](https://webviewer-docs.mupdf.com/api-reference/refs/index#event)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.