> ## 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

<ParamField body="selector" type="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`.
</ParamField>

<ParamField body="docURL" type="string" required>
  The URL of the document you wish to display.
</ParamField>

<ParamField body="options" type="object">
  Optional initialization options.
</ParamField>

<Expandable title="options properties">
  <ParamField body="options.licenseKey" type="string">
    The [license key](https://webviewer.mupdf.com/pricing) to use.
  </ParamField>

  <ParamField body="options.libraryPath" type="string">
    Library path for library assets. See [Optionally set the library path](/getting-started#optionally-set-the-library-path).
  </ParamField>

  <ParamField body="options.filename" type="string">
    Filename for the PDF.
  </ParamField>

  <ParamField body="options.standalone" type="boolean">
    Whether to run in standalone mode.
  </ParamField>

  <ParamField body="options.withoutLoader" type="boolean">
    Whether to hide the document loader.
  </ParamField>

  <ParamField body="options.author" type="string">
    Default author used in annotation metadata.
  </ParamField>
</Expandable>

#### Returns

<ResponseField name="result" type="Promise<MuPDFWebViewer>" required>
  A Promise that resolves to a `MuPDFWebViewer` instance.
</ResponseField>

**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](/api-reference/document/index)
  * [`document`](/api-reference/document/index#document)
    * [`document.open()`](/api-reference/document/index#open)
    * [`document.download()`](/api-reference/document/index#download)
    * [`document.getPages()`](/api-reference/document/index#getpages)
    * [`document.getPageCount()`](/api-reference/document/index#getpagecount)
    * [`document.close()`](/api-reference/document/index#close)
    * [`document.print()`](/api-reference/document/index#print)
    * [`document.rotatePage()`](/api-reference/document/index#rotatepage)
    * [`document.getText()`](/api-reference/document/index#gettext)
    * [`document.export()`](/api-reference/document/index#export)

***

### `viewer` instance

The viewer user interface used for interaction.

<a id="api-viewer" />

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

***

### `watermark` instance

An interface to manage document watermarks.

* [Watermark API](/api-reference/watermark/index)
  * [`watermark`](/api-reference/watermark/index#watermark)
    * [`watermark.create()`](/api-reference/watermark/index#create)

***

### `capture` instance

The interface for capturing images from a document.

* [Capture API](/api-reference/capture/index)
  * [`capture`](/api-reference/capture/index#capture)
    * [`capture.selectAndExport()`](/api-reference/capture/index#selectandexport)

***

### `text` instance

The interface for the document text.

* [Text API](/api-reference/text/index)
  * [`text`](/api-reference/text/index#text)
    * [`text.search()`](/api-reference/text/index#search)
    * [`text.locateSource()`](/api-reference/text/index#locatesource)
    * [`text.getSelected()`](/api-reference/text/index#getselected)

***

### `annotation` instance

An interface for managing document annotations.

* [Annotation API](/api-reference/annotation/index)
  * [`annotation`](/api-reference/annotation/index#annotation)
    * [`annotation.remove()`](/api-reference/annotation/index#remove)
    * [`annotation.get()`](/api-reference/annotation/index#get)
    * [`annotation.add()`](/api-reference/annotation/index#add)
    * [`annotation.set()`](/api-reference/annotation/index#set)
    * [`annotation.undo()`](/api-reference/annotation/index#undo)
    * [`annotation.redo()`](/api-reference/annotation/index#redo)

***

### `redaction` instance

An interface for managing document redactions.

* [Redaction API](/api-reference/redaction/index)
  * [`redaction`](/api-reference/redaction/index#redaction)
    * [`redaction.get()`](/api-reference/redaction/index#get)
    * [`redaction.set()`](/api-reference/redaction/index#set)
    * [`redaction.add()`](/api-reference/redaction/index#add)
    * [`redaction.remove()`](/api-reference/redaction/index#remove)
    * [`redaction.apply()`](/api-reference/redaction/index#apply)
  * [`Redaction Types`](/api-reference/redaction/index#redaction-types)

***

### `toast` instance

An object used to display messages.

* [Toast API](/api-reference/toast/index)
  * [`toast`](/api-reference/toast/index#toast)
    * [`toast.show()`](/api-reference/toast/index#show)

## Events

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

* [Events API](/api-reference/events/index)

## References

A glossary of object references.

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