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
An object containing the dialog to show or hide.
webViewer.refs.dialog.type
required
Use to explicitly show or hide instead of toggling.
Returns
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 containing the scale number.
Returns
Example
zoomIn
Zooms in on the document.
Parameters
Increment amount. Required when config is provided.
Returns
Example
zoomOut
Zooms out on the document.
Parameters
Decrement amount. Required when config is provided.
Returns
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 containing rotation value.
webViewer.refs.degree
required
Returns
Example
rotateClockwise
Rotates clockwise.
Returns
Example
rotateCounterClockwise
Rotates counter-clockwise.
Returns
Example
setViewMode
Sets the view mode for the document.
Parameters
Object containing the view mode.
webViewer.refs.viewMode
required
Returns
Example
fitTo
Sets the page fitting.
Parameters
Object containing the page fitting type.
webViewer.refs.fit.to
required
Returns
Example
Scrolls to a specific position on a page or to an annotation.
Parameters
The configuration object.
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
scrollToNextPage
Scrolls to the next page.
Returns
Example
scrollToPreviousPage
Scrolls to the previous page.
Returns
Example
Selects an annotation tool.
Parameters
The configuration object.
webViewer.refs.annotation.tool
required
Returns
Example
Toggles an annotation tool.
Parameters
The configuration object.
webViewer.refs.annotation.tool
required
Returns
Example
openSideView
Opens a side view panel.
Parameters
An object containing the side view panel to open.
webViewer.refs.panel.open
required
Returns
Example
closeSideView
Closes a side view panel.
Parameters
An object containing the side view panel to close.
webViewer.refs.panel.close
required
Returns
Example
togglePanel
Toggles a panel visibility.
Parameters
An object containing the side view to toggle.
webViewer.refs.panel.open
required
Returns
Example
highlight
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
Keyword to search and highlight.
Highlight opacity.
Whether to perform case-sensitive matching.
Whether to interpret keyword as a regular expression.
Returns
Promise<HighlightedRect[]>
required
A Promise that resolves to an array of highlighted rects.
Example
unhighlight
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
searchText
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
setViewVisibility
Sets a view visibility.
Parameters
The configuration object.
webViewer.refs.visibility.view
required
Boolean indicating visibility state.
Returns
Adds button items to the toolbar.
Parameters
The configuration object.
Array of button definitions.
Show buttons item properties
Button position: "TOOLBAR.LEFT_SECTION.FIRST" or "TOOLBAR.LEFT_SECTION.LAST" or "TOOLBAR.RIGHT_SECTION.FIRST" or "TOOLBAR.RIGHT_SECTION.LAST".
webViewer.refs.icon
required
Button label (tooltip text on hover).
Button title (printed text next to the icon).
Returns
Opens the context menu.
Returns
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
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
Defines the popup menu when selecting text
Parameters
The configuration object.
Returns
Defines the popup menu when selecting or creating an annotation.
Parameters
The configuration object.
HTML content of the menu.
JavaScript content of the menu.
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
Defines a right-click action on the content area.
Parameters
The configuration object.
setBackgroundColor
Sets the background color behind the document page.
Parameters
An object containing the color as a hexadecimal string.
Returns
Example
setPageBorderColor
Sets the border color around document page instances in the viewer.
Parameters
An object containing the color as a hexadecimal string.
Returns
Example
setColor
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
setTheme
Sets the overall theme of the viewer UI.
Parameters
An object containing the theme type.
webViewer.refs.theme
required
Returns
Example
setLanguage
Sets the language for the UI.
Parameters
The configuration object.
webViewer.refs.language
required
Returns
getSize
Gets the viewer size.
Returns
Promise<{ width: number; height: number; }>
required
A Promise that resolves to the viewer size.
Example
setLogo
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
Supporting Types
These types are used by the viewer APIs on this page.
HighlightRect
HighlightKeyword
HighlightedRect