Skip to main content
The viewer object is an instance accessible from the main MuPDFWebViewer instance as follows:
This assumes you have returned your instance name as webViewer from the initMuPDFWebViewer() promise!

viewer

The viewer object has the following methods:

toggleDialog

Toggles, shows or hides the print or search dialog.

Parameters

object
required
An object containing the dialog to show or hide.

Returns

Promise
required
A Promise.
Example

getScale

Gets the current zoom scale.

Returns

Promise<{ scale: number; }>
required
A Promise that resolves to the current zoom scale.
Example

setScale

Sets the current zoom scale.

Parameters

object
required
Object containing the scale number.

Returns

Promise
required
A Promise.
Example

zoomIn

Zooms in on the document.

Parameters

object
Optional configuration.

Returns

Promise
required
A Promise.
Example

zoomOut

Zooms out on the document.

Parameters

object
Optional configuration.

Returns

Promise
required
A Promise.
Example

getCurrentPageIndex

Gets the current page index (zero-indexed).

Returns

Promise<{ currentPageIndex: number; }>
required
A Promise that resolves to the current page index (zero-indexed).
Example

getRotation

Gets the current document rotation angle in degrees.

Returns

Promise<{ degree: 0 | 90 | 180 | 270 }>
required
A Promise.
Example

setRotation

Sets the document rotation angle in degrees.

Parameters

object
required
Object containing rotation value.

Returns

Promise
required
A Promise.
Example

rotateClockwise

Rotates clockwise.

Returns

Promise
required
A Promise.
Example

rotateCounterClockwise

Rotates counter-clockwise.

Returns

Promise
required
A Promise.
Example

setViewMode

Sets the view mode for the document.

Parameters

object
required
Object containing the view mode.

Returns

Promise
required
A Promise.
Example

fitTo

Sets the page fitting.

Parameters

object
required
Object containing the page fitting type.

Returns

Promise
required
A Promise.
Example

scrollTo

Scrolls to a specific position on a page or to an annotation.

Parameters

object
required
The configuration object.
Use one of these overload shapes:
  • { type: 'PAGE', value: number, centerPoint?: { x: number; y: number } }
  • { type: 'ANNOTATION', value: number, select?: boolean }
  • { type: 'ANNOTATION', name: string, pageIndex: number, select?: boolean }

Returns

Promise
required
A Promise.
Example

scrollToNextPage

Scrolls to the next page.

Returns

Promise
required
A Promise.
Example

scrollToPreviousPage

Scrolls to the previous page.

Returns

Promise
required
A Promise.
Example

selectAnnotationTool

Selects an annotation tool.

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.
Example

toggleAnnotationTool

Toggles an annotation tool.

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.
Example

openSideView

Opens a side view panel.

Parameters

object
required
An object containing the side view panel to open.

Returns

Promise
required
A Promise.
Example

closeSideView

Closes a side view panel.

Parameters

object
required
An object containing the side view panel to close.

Returns

Promise
required
A Promise.
Example

togglePanel

Toggles a panel visibility.

Parameters

object
required
An object containing the side view to toggle.

Returns

Promise
required
A Promise.
Example

highlight

Highlights text.

Parameters

object
required
The configuration object.

Returns

Promise<HighlightedRect[]>
required
A Promise that resolves to an array of highlighted rects.
Example

unhighlight

Removes highlights.

Parameters

object
required
The configuration object. Provide either rects or mode.

Returns

Promise
required
A Promise.
Example

searchText

Searches for text. This will open up the search panel if it is not already opened and run the search.

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.
Example

setViewVisibility

Sets a view visibility.

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.

addButton

Adds button items to the toolbar.

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.

openContextMenu

Opens the context menu.

Returns

Promise
required
A Promise.

addContextMenu

Adds items to the context menu (this is the pop-up menu you see when you right click on a document).

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.

defineDocumentPanel

Defines document panel at the left side of the viewer toolbar.

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.

defineTextSelectionMenu

Defines the popup menu when selecting text

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.

defineAnnotSelectMenu

Defines the popup menu when selecting or creating an annotation.

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.
When using style or script, please consider the following
  • style: CSS selectors will apply to all matching elements within the viewer scope.
  • script: JavaScript code will be executed in the viewer’s context with the following limitations:
    • External resources cannot be accessed.
    • Variables declared will be in global scope.

defineRightClickAction

Defines a right-click action on the content area.

Parameters

object
required
The configuration object.

setBackgroundColor

Sets the background color behind the document page.

Parameters

object
required
An object containing the color as a hexadecimal string.

Returns

Promise
required
A Promise.
Example

setPageBorderColor

Sets the border color around document page instances in the viewer.

Parameters

object
required
An object containing the color as a hexadecimal string.

Returns

Promise
required
A Promise.
Example

setColor

Sets the primary (mainColor) and secondary (subColor) for the viewer user-interface.

Parameters

object
required
An object containing the mainColor and subColor hex color strings.

Returns

Promise
required
A Promise.
Example

setTheme

Sets the overall theme of the viewer UI.

Parameters

object
required
An object containing the theme type.

Returns

Promise
required
A Promise.
Example

setLanguage

Sets the language for the UI.

Parameters

object
required
The configuration object.

Returns

Promise
required
A Promise.

getSize

Gets the viewer size.

Returns

Promise<{ width: number; height: number; }>
required
A Promise that resolves to the viewer size.
Example
Sets the brand logo (maximum size: 100x24px). It displays the logo in the top center of the viewer.

Parameters

object
required
An object containing a link to the logo image.

Returns

Promise
required
A Promise.
Example

Supporting Types

These types are used by the viewer APIs on this page.

AnnotationTool

AnnotationStampTool

HighlightRect

HighlightKeyword

HighlightedRect