Skip to main content

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.

The viewer object is an instance accessible from the main MuPDFWebViewer instance as follows:
const viewer = webViewer.viewer;
This assumes you have returned your instance name as webViewer from the initMuPDFWebViewer() promise!

viewer

The viewer object has the following methods:

toggleDialog

toggleDialog(config: { dialogType: DialogType; visibility?: boolean }): Promise<undefined>;
Toggles, shows or hides the print or search dialog.

Parameters

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

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.toggleDialog({dialogType: webViewer.refs.dialog.type.PRINT, visibility:true});

getScale

getScale(): Promise<{ scale: number }>;
Gets the current zoom scale.

Returns

result
Promise<{ scale: number; }>
required
A Promise that resolves to the current zoom scale.
Example
async function getScale() {
    return webViewer.viewer.getScale();
}

function success(result) {
    console.log(`Scale is: ${result.scale}`);
}

function failure(error) {
    console.error(`Error: ${error}`);
}

getScale().then(success, failure);

setScale

setScale(config: { scale: number }): Promise<undefined>;
Sets the current zoom scale.

Parameters

config
object
required
Object containing the scale number.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.setScale({scale:140});

zoomIn

zoomIn(config?: { increment: number }): Promise<undefined>;
Zooms in on the document.

Parameters

config
object
Optional configuration.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.zoomIn({increment:10});

zoomOut

zoomOut(config?: { decrement: number }): Promise<undefined>;
Zooms out on the document.

Parameters

config
object
Optional configuration.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.zoomOut({decrement:10});

getCurrentPageIndex

getCurrentPageIndex(): Promise<{ currentPageIndex: number }>;
Gets the current page index (zero-indexed).

Returns

result
Promise<{ currentPageIndex: number; }>
required
A Promise that resolves to the current page index (zero-indexed).
Example
async function getPageIndex() {
    return webViewer.viewer.getCurrentPageIndex();
}

function success(result) {
    console.log(`Page index is: ${result.currentPageIndex}`);
}

function failure(error) {
    console.error(`Error: ${error}`);
}

getPageIndex().then(success, failure);

getRotation

getRotation(): Promise<{ degree: 0 | 90 | 180 | 270 }>;
Gets the current document rotation angle in degrees.

Returns

result
Promise<{ degree: 0 | 90 | 180 | 270 }>
required
A Promise.
Example
async function getRotation() {
    return webViewer.viewer.getRotation();
}

function success(result) {
    console.log(`Rotation is: ${result.degree}`);
}

function failure(error) {
    console.error(`Error: ${error}`);
}

getRotation().then(success, failure);

setRotation

setRotation(config: { degree: 0 | 90 | 180 | 270 | 360 }): Promise<undefined>;
Sets the document rotation angle in degrees.

Parameters

config
object
required
Object containing rotation value.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.setRotation({ degree: webViewer.refs.degree.DEG_90 });

rotateClockwise

rotateClockwise(): Promise<undefined>;
Rotates clockwise.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.rotateClockwise();

rotateCounterClockwise

rotateCounterClockwise(): Promise<undefined>;
Rotates counter-clockwise.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.rotateCounterClockwise();

setViewMode

setViewMode(config: { viewMode: ViewMode }): Promise<undefined>;
Sets the view mode for the document.

Parameters

config
object
required
Object containing the view mode.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.setViewMode({viewMode:webViewer.refs.viewMode.DOUBLE});

fitTo

fitTo(config: { to: FitMode }): Promise<undefined>;
Sets the page fitting.

Parameters

config
object
required
Object containing the page fitting type.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.fitTo({to:webViewer.refs.fit.to.WIDTH});

scrollTo

scrollTo(config: { type: ScrollType; value: number }): Promise<undefined>;
scrollTo(config: { type: 'PAGE'; value: number; centerPoint?: { x: number; y: number } }): Promise<undefined>;
scrollTo(config: { type: 'ANNOTATION'; value: number; select?: boolean }): Promise<undefined>;
scrollTo(config: { type: 'ANNOTATION'; name: string; pageIndex: number; select?: boolean }): Promise<undefined>;
Scrolls to a specific position on a page or to an annotation.

Parameters

config
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

result
Promise
required
A Promise.
Example
// scroll to page 4 of the document
webViewer.viewer.scrollTo({type:webViewer.refs.scroll.type.PAGE, value:3});

scrollToNextPage

scrollToNextPage(): Promise<undefined>;
Scrolls to the next page.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.scrollToNextPage();

scrollToPreviousPage

scrollToPreviousPage(): Promise<undefined>;
Scrolls to the previous page.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.scrollToPreviousPage();

selectAnnotationTool

selectAnnotationTool(config: AnnotationTool | AnnotationStampTool): Promise<undefined>;
Selects an annotation tool.

Parameters

config
object
required
The configuration object.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.selectAnnotationTool({tool:webViewer.refs.annotation.tool.HIGHLIGHT});

toggleAnnotationTool

toggleAnnotationTool(config: AnnotationTool | AnnotationStampTool): Promise<undefined>;
Toggles an annotation tool.

Parameters

config
object
required
The configuration object.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.toggleAnnotationTool({tool:webViewer.refs.annotation.tool.HIGHLIGHT});

openSideView

openSideView(config: { type: Panel }): Promise<undefined>;
Opens a side view panel.

Parameters

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

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.openSideView({type:webViewer.refs.panel.open.BOOKMARK})

closeSideView

closeSideView(config: { type: PanelSide }): Promise<undefined>;
Closes a side view panel.

Parameters

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

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.closeSideView({type: webViewer.refs.panel.close.RIGHT});

togglePanel

togglePanel(config: { type: Panel }): Promise<undefined>;
Toggles a panel visibility.

Parameters

config
object
required
An object containing the side view to toggle.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.togglePanel({type:webViewer.refs.panel.open.BOOKMARK});

highlight

highlight(config: { rects: HighlightRect[] }): Promise<HighlightedRect[]>;
highlight(config: { keywords: HighlightKeyword[] }): Promise<HighlightedRect[]>;
Highlights text.

Parameters

config
object
required
The configuration object.

Returns

result
Promise<HighlightedRect[]>
required
A Promise that resolves to an array of highlighted rects.
Example
webViewer.viewer.highlight({rects:[{color:"#ff00ff", pageIndex:0, rect:{left:0,right:100,top:0, bottom:100}}]});

unhighlight

unhighlight(config: { rects: HighlightedRect[] }): Promise<undefined>;
unhighlight(config: { mode: 'all' }): Promise<undefined>;
Removes highlights.

Parameters

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

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.unhighlight({rects:[{id:12}, {id:43}]});
webViewer.viewer.unhighlight({mode:"all"}); // removes all highlights

searchText

searchText(config: {
  keyword: string;
  caseSensitive?: boolean;
  useRegex?: boolean;
  emitEvent?: boolean;
}): Promise<undefined>;
Searches for text. This will open up the search panel if it is not already opened and run the search.

Parameters

config
object
required
The configuration object.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.searchText({keyword:"hello", caseSensitive:false})

setViewVisibility

setViewVisibility(config: { view: HidableView; visibility: boolean }): Promise<undefined>;
Sets a view visibility.

Parameters

config
object
required
The configuration object.

Returns

result
Promise
required
A Promise.

addButton

addButton(config: {
  buttons: {
    position: 'TOOLBAR.LEFT_SECTION.FIRST' | 'TOOLBAR.LEFT_SECTION.LAST' | 'TOOLBAR.RIGHT_SECTION.FIRST' | 'TOOLBAR.RIGHT_SECTION.LAST';
    icon: IconName;
    label: string;
    onclick: Function;
    title?: string;
  }[];
}): Promise<undefined>;
Adds button items to the toolbar.

Parameters

config
object
required
The configuration object.

Returns

result
Promise
required
A Promise.

openContextMenu

openContextMenu(): Promise<undefined>;
Opens the context menu.

Returns

result
Promise
required
A Promise.

addContextMenu

addContextMenu(config: {
  menus: {
    type: 'MENU';
    position: 'FIRST' | 'LAST';
    icon?: string;
    label?: string;
    onclick?: Function;
  }[];
}): Promise<undefined>;
Adds items to the context menu (this is the pop-up menu you see when you right click on a document).

Parameters

config
object
required
The configuration object.

Returns

result
Promise
required
A Promise.

defineDocumentPanel

defineDocumentPanel(config: {
  items: {
    label: string;
    onclick: Function;
    icon?: string;
  }[];
}): Promise<undefined>;
Defines document panel at the left side of the viewer toolbar.

Parameters

config
object
required
The configuration object.

Returns

result
Promise
required
A Promise.

defineTextSelectionMenu

defineTextSelectionMenu(config: {
  menus: {
    label: string;
    onclick: Function;
    icon?: IconName;
  };
}): Promise<undefined>;
Defines the popup menu when selecting text

Parameters

config
object
required
The configuration object.

Returns

result
Promise
required
A Promise.

defineAnnotSelectMenu

defineAnnotSelectMenu(config: {
  html: string;
  style?: string;
  script?: string;
  tool?: AnnotType;
}): Promise<undefined>;
Defines the popup menu when selecting or creating an annotation.

Parameters

config
object
required
The configuration object.

Returns

result
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

defineRightClickAction(config: { onclick: Function }): Promise<undefined>;
Defines a right-click action on the content area.

Parameters

config
object
required
The configuration object.

setBackgroundColor

setBackgroundColor(config: { color: string }): Promise<undefined>;
Sets the background color behind the document page.

Parameters

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

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.setBackgroundColor({color: "#222222"});

setPageBorderColor

setPageBorderColor(config: { color: string }): Promise<undefined>;
Sets the border color around document page instances in the viewer.

Parameters

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

Returns

result
Promise
required
A Promise.
Example
viewer.setPageBorderColor({color: "#ff0000"});

setColor

setColor(config: { mainColor: string; subColor: string }): Promise<undefined>;
Sets the primary (mainColor) and secondary (subColor) for the viewer user-interface.

Parameters

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

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.setColor({mainColor: "#00ff00", subColor: "#0000ff"});

setTheme

setTheme(config: { type: Theme }): Promise<undefined>;
Sets the overall theme of the viewer UI.

Parameters

config
object
required
An object containing the theme type.

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.setTheme({type:webViewer.refs.theme.DARK_MODE});

setLanguage

setLanguage(config: { key: Language }): Promise<undefined>;
Sets the language for the UI.

Parameters

config
object
required
The configuration object.

Returns

result
Promise
required
A Promise.
webViewer.viewer.setLanguage({ key: webViewer.refs.language.ENGLISH });

getSize

getSize(): Promise<TSize>;
Gets the viewer size.

Returns

result
Promise<{ width: number; height: number; }>
required
A Promise that resolves to the viewer size.
Example
async function getSize() {
    return webViewer.viewer.getSize();
}

function success(result) {
    console.log(`Size is: ${result.width}x${result.height}`);
}

function failure(error) {
    console.error(`Error: ${error}`);
}

getSize().then(success, failure);
setLogo(config: { url: string }): Promise<undefined>;
Sets the brand logo (maximum size: 100x24px). It displays the logo in the top center of the viewer.

Parameters

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

Returns

result
Promise
required
A Promise.
Example
webViewer.viewer.setLogo({url: "/logo.png"});

Supporting Types

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

AnnotationTool

export interface AnnotationTool {
  tool: AnnotType;
  annotation?: {
    opacity?: number;
    strokeColor?: string;
    strokeWidth?: number;
    fillColor?: string;
    strokeDashPattern?: number[];
    startPointStyle?: LineEnd;
    endPointStyle?: LineEnd;
    fontColor?: string;
    fontFamily?: string;
    fontSize?: number;
  };
}

AnnotationStampTool

export interface AnnotationStampTool {
  tool: AnnotType;
  width?: number;
  height?: number;
}

HighlightRect

export interface HighlightRect {
  color: string;
  pageIndex: number;
  opacity?: number;
  rect: TRect;
}

HighlightKeyword

export interface HighlightKeyword {
  keyword: string;
  color: string;
  opacity?: number;
  caseSensitive?: boolean;
  useRegex?: boolean;
}

HighlightedRect

export interface HighlightedRect {
  id: number;
}