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
An object containing the dialog to show or hide.
config.dialogType
webViewer.refs.dialog.type
required
Use to explicitly show or hide instead of toggling.
Returns
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
Object containing the scale number.
Returns
Example
webViewer.viewer.setScale({scale:140});
zoomIn
zoomIn(config?: { increment: number }): Promise<undefined>;
Zooms in on the document.
Parameters
Increment amount. Required when config is provided.
Returns
Example
webViewer.viewer.zoomIn({increment:10});
zoomOut
zoomOut(config?: { decrement: number }): Promise<undefined>;
Zooms out on the document.
Parameters
Decrement amount. Required when config is provided.
Returns
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
Object containing rotation value.
config.degree
webViewer.refs.degree
required
Returns
Example
webViewer.viewer.setRotation({ degree: webViewer.refs.degree.DEG_90 });
rotateClockwise
rotateClockwise(): Promise<undefined>;
Rotates clockwise.
Returns
Example
webViewer.viewer.rotateClockwise();
rotateCounterClockwise
rotateCounterClockwise(): Promise<undefined>;
Rotates counter-clockwise.
Returns
Example
webViewer.viewer.rotateCounterClockwise();
setViewMode
setViewMode(config: { viewMode: ViewMode }): Promise<undefined>;
Sets the view mode for the document.
Parameters
Object containing the view mode.
config.viewMode
webViewer.refs.viewMode
required
Returns
Example
webViewer.viewer.setViewMode({viewMode:webViewer.refs.viewMode.DOUBLE});
fitTo
fitTo(config: { to: FitMode }): Promise<undefined>;
Sets the page fitting.
Parameters
Object containing the page fitting type.
config.to
webViewer.refs.fit.to
required
Returns
Example
webViewer.viewer.fitTo({to:webViewer.refs.fit.to.WIDTH});
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
The configuration object.
config.type
webViewer.refs.scroll.type
required
Scroll value. Required for { type: 'PAGE' } and { type: 'ANNOTATION', value: number } overloads.
Center point of the page ({ x: number, y: number }). Only used when type is webViewer.refs.scroll.type.PAGE.
Whether to select the annotation. Only used when type is webViewer.refs.scroll.type.ANNOTATION.
Annotation name. Required for { type: 'ANNOTATION', name: string, pageIndex: number }.
Page index. Required for { type: 'ANNOTATION', name: string, pageIndex: number }.
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
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
Example
webViewer.viewer.scrollToNextPage();
scrollToPreviousPage
scrollToPreviousPage(): Promise<undefined>;
Scrolls to the previous page.
Returns
Example
webViewer.viewer.scrollToPreviousPage();
selectAnnotationTool(config: AnnotationTool | AnnotationStampTool): Promise<undefined>;
Selects an annotation tool.
Parameters
The configuration object.
config.tool
webViewer.refs.annotation.tool
required
Returns
Example
webViewer.viewer.selectAnnotationTool({tool:webViewer.refs.annotation.tool.HIGHLIGHT});
toggleAnnotationTool(config: AnnotationTool | AnnotationStampTool): Promise<undefined>;
Toggles an annotation tool.
Parameters
The configuration object.
config.tool
webViewer.refs.annotation.tool
required
Returns
Example
webViewer.viewer.toggleAnnotationTool({tool:webViewer.refs.annotation.tool.HIGHLIGHT});
openSideView
openSideView(config: { type: Panel }): Promise<undefined>;
Opens a side view panel.
Parameters
An object containing the side view panel to open.
config.type
webViewer.refs.panel.open
required
Returns
Example
webViewer.viewer.openSideView({type:webViewer.refs.panel.open.BOOKMARK})
closeSideView
closeSideView(config: { type: PanelSide }): Promise<undefined>;
Closes a side view panel.
Parameters
An object containing the side view panel to close.
config.type
webViewer.refs.panel.close
required
Returns
Example
webViewer.viewer.closeSideView({type: webViewer.refs.panel.close.RIGHT});
togglePanel
togglePanel(config: { type: Panel }): Promise<undefined>;
Toggles a panel visibility.
Parameters
An object containing the side view to toggle.
config.type
webViewer.refs.panel.open
required
Returns
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
The configuration object.
Array of highlight region definitions.
Array of keyword highlight definitions.
Show rects item properties
Highlight area rect ({ top: number; left: number; bottom: number; right: number }).
Show keywords item properties
config.keywords[].keyword
Keyword to search and highlight.
config.keywords[].opacity
Highlight opacity.
config.keywords[].caseSensitive
Whether to perform case-sensitive matching.
config.keywords[].useRegex
Whether to interpret keyword as a regular expression.
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
The configuration object. Provide either rects or mode.
Array of highlighted rect references to remove.
Mode for unhighlighting (for example, "all" to remove all highlights).
Show HighlightedRect properties
Returns
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
The configuration object.
Whether to be case sensitive.
Whether to use regular expressions.
Returns
Example
webViewer.viewer.searchText({keyword:"hello", caseSensitive:false})
setViewVisibility
setViewVisibility(config: { view: HidableView; visibility: boolean }): Promise<undefined>;
Sets a view visibility.
Parameters
The configuration object.
config.view
webViewer.refs.visibility.view
required
Boolean indicating visibility state.
Returns
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
The configuration object.
Array of button definitions.
Show buttons item properties
config.buttons[].position
Button position: "TOOLBAR.LEFT_SECTION.FIRST" or "TOOLBAR.LEFT_SECTION.LAST" or "TOOLBAR.RIGHT_SECTION.FIRST" or "TOOLBAR.RIGHT_SECTION.LAST".
config.buttons[].icon
webViewer.refs.icon
required
Button label (tooltip text on hover).
Button title (printed text next to the icon).
Returns
openContextMenu(): Promise<undefined>;
Opens the context menu.
Returns
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
The configuration object.
Array of menu definitions.
Show menus item properties
Item position: "FIRST" or "LAST".
Returns
defineDocumentPanel
defineDocumentPanel(config: {
items: {
label: string;
onclick: Function;
icon?: string;
}[];
}): Promise<undefined>;
Defines document panel at the left side of the viewer toolbar.
Parameters
The configuration object.
Array of panel item definitions.
Show items item properties
Returns
defineTextSelectionMenu(config: {
menus: {
label: string;
onclick: Function;
icon?: IconName;
};
}): Promise<undefined>;
Defines the popup menu when selecting text
Parameters
The configuration object.
Returns
defineAnnotSelectMenu(config: {
html: string;
style?: string;
script?: string;
tool?: AnnotType;
}): Promise<undefined>;
Defines the popup menu when selecting or creating an annotation.
Parameters
The configuration object.
HTML content of the menu.
JavaScript content of the menu.
config.tool
webViewer.refs.annotation.tool
Returns
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
The configuration object.
setBackgroundColor
setBackgroundColor(config: { color: string }): Promise<undefined>;
Sets the background color behind the document page.
Parameters
An object containing the color as a hexadecimal string.
Returns
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
An object containing the color as a hexadecimal string.
Returns
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
An object containing the mainColor and subColor hex color strings.
Primary color in format #RRGGBB.
Secondary color in format #RRGGBB.
Returns
Example
webViewer.viewer.setColor({mainColor: "#00ff00", subColor: "#0000ff"});
setTheme
setTheme(config: { type: Theme }): Promise<undefined>;
Sets the overall theme of the viewer UI.
Parameters
An object containing the theme type.
config.type
webViewer.refs.theme
required
Returns
Example
webViewer.viewer.setTheme({type:webViewer.refs.theme.DARK_MODE});
setLanguage
setLanguage(config: { key: Language }): Promise<undefined>;
Sets the language for the UI.
Parameters
The configuration object.
config.key
webViewer.refs.language
required
Returns
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
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
An object containing a link to the logo image.
Returns
Example
webViewer.viewer.setLogo({url: "/logo.png"});
Supporting Types
These types are used by the viewer APIs on this page.
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;
};
}
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;
}