Class: DocumentViewer

CoreControls. DocumentViewer

Represents a full-featured control used for displaying a Document. The viewer supports text selection and text search, and several page view modes.

new DocumentViewer()

Creates a new empty DocumentViewer.
Properties:
Name Type Description
defaults object Default values for document viewer. Set FitMode, DisplayMode or Zoom.

Extends

Members


<static> Events

Properties:
Name Type Description
ACTIVE_SEARCH_RESULT_CHANGED string CoreControls.DocumentViewer.activeSearchResultChanged
MOUSE_LEFT_UP string CoreControls.DocumentViewer.mouseLeftUp
MOUSE_LEFT_DOWN string CoreControls.DocumentViewer.mouseLeftDown
CLICK string CoreControls.DocumentViewer.click
TAP string CoreControls.DocumentViewer.tap
DBL_CLICK string CoreControls.DocumentViewer.dblClick
KEY_DOWN string CoreControls.DocumentViewer.keyDown
KEY_UP string CoreControls.DocumentViewer.keyUp
MOUSE_ENTER string CoreControls.DocumentViewer.mouseEnter
MOUSE_MOVE string CoreControls.DocumentViewer.mouseMove
MOUSE_LEAVE string CoreControls.DocumentViewer.mouseLeave
MOUSE_RIGHT_DOWN string CoreControls.DocumentViewer.mouseRightDown
MOUSE_RIGHT_UP string CoreControls.DocumentViewer.mouseRightUp
DOCUMENT_UNLOADED string CoreControls.DocumentViewer.documentUnloaded
ANNOTATIONS_LOADED string CoreControls.DocumentViewer.annotationsLoaded
BEFORE_DOCUMENT_LOADED string CoreControls.DocumentViewer.beforeDocumentLoaded
DOCUMENT_LOADED string CoreControls.DocumentViewer.documentLoaded
DISPLAY_PAGE_LOCATION string CoreControls.DocumentViewer.displayPageLocation
NOTIFY string CoreControls.DocumentViewer#event:notify
SEARCH_IN_PROGRESS string CoreControls.DocumentViewer.searchInProgress
TEXT_SELECTED string CoreControls.DocumentViewer.textSelected
TOOL_MODE_UPDATED string CoreControls.DocumentViewer.toolModeUpdated
FIT_MODE_UPDATED string CoreControls.DocumentViewer.fitModeUpdated
ROTATION_UPDATED string CoreControls.DocumentViewer.rotationUpdated
ZOOM_UPDATED string CoreControls.DocumentViewer.zoomUpdated
PAGE_NUMBER_UPDATED string CoreControls.DocumentViewer.pageNumberUpdated
CHANGE_PAGE string CoreControls.DocumentViewer.changePage
LAYOUT_CHANGED string CoreControls.DocumentViewer.layoutChanged
PAGE_COMPLETE string CoreControls.DocumentViewer.pageComplete
DISPLAY_MODE_UPDATED string CoreControls.DocumentViewer.displayModeUpdated
BEGIN_RENDERING string CoreControls.DocumentViewer.beginRendering
FINISHED_RENDERING string CoreControls.DocumentViewer.finishedRendering
TOOL_UPDATED string CoreControls.DocumentViewer.toolUpdated

<static> FitMode

Contains a list of available fit modes for the DocumentViewer.
Properties:
Name Type Description
FitWidth function Zoom level is constrained such that the current page's width will exactly fill the available space.
FitPage function Zoom level is constrained such that the current page's width or height will exactly fill the available space.
Zoom function Zoom level is not constrained.

<static> SearchResults

The code indicating the reason that the search process concluded.
Properties:
Name Type Description
ambientStr string The text surrounding the result string.
resultStr string The found text.
resultStrStart number The index in ambient string where the result string starts.
resultStrEnd number The index in ambient string where the result string end.
pageNum number The page number which the search was conducted on.
resultCode number The reason the search completed.
quads object A list of Quads, representing the bounding box(es) of the found text. Useful for highlighting the text.

SnapMode

Enum for snap mode values. Snap modes control which point within the page is considered as the queried point.
Properties:
Name Type Description
DEFAULT number
POINT_ON_LINE number
LINE_MID_POINT number
LINE_INTERSECTION number
PATH_ENDPOINT number

Methods


clearSearchResults()

Clears all search results from the viewer

clearSelection()

Clears any selected text on the all pages.

closeDocument()

Reinitializes data and clears the viewer area content.

displayAdditionalSearchResult(result)

Displays the new search result without clearing previous results
Parameters:
Name Type Description
result object The result of a search, CoreControls.DocumentViewer.SearchResult Returned by onResult in CoreControls.DocumentViewer#textSearchInit.

displayAdditionalSearchResults(results)

Displays the new search results without clearing previous results If you need to display many results at the same time this can be much more efficient than calling displayAdditionalSearchResult for each result
Parameters:
Name Type Description
results Array.<object> An array of search results CoreControls.DocumentViewer.SearchResult. Returned by onResult in CoreControls.DocumentViewer#textSearchInit.

displayBookmark(bookmark)

If the boomark is an internal link then it scrolls the viewer so that the position of the bookmark is in the upper-left corner of the viewer. If it's an external URL then it opens the URL.
Parameters:
Name Type Description
bookmark Bookmark A bookmark that specifies the location to go to. Returned by CoreControls.Document#getBookmarks.

displayFirstPage()

Scrolls the viewer so that the upper-left corner of the Document's first page is in the upper-left corner of the viewer.

displayLastPage()

Scrolls the viewer so that the upper-left corner of the Document's last page is in the upper-left corner of the viewer.

displayPageLocation(pageNumber, horizontalPosition, verticalPostion [, doNotJumpIfInView])

Shifts the current viewport of the viewer such that it can display the specified viewer coordinate position Please refer to https://www.pdftron.com/documentation/web/guides/coordinates/#viewer-page-coordinates for more details
Parameters:
Name Type Argument Description
pageNumber number The page number the location is on
horizontalPosition number The horizontal position from the x-axis origin of the page (in viewer page coordinates)
verticalPostion number The vertical position from the y-axis of the page (in viewer page coordinates)
doNotJumpIfInView boolean <optional>
If true then if the page location is currently in view don't cause the viewer to shift

displaySearchResult(result [, jump])

Scrolls the viewer so that the position of the search result is in the middle of the viewer.
Parameters:
Name Type Argument Description
result object The result of a search, CoreControls.DocumentViewer.SearchResult. Returned by onResult in CoreControls.DocumentViewer#textSearchInit.
jump function <optional>
The callback for navigating to the found result. This is optional and will jump to the correct location in the DocumentViewer if no parameter is passed.

dispose()

Disposes the current document's data

drawSelection(pageNumber)

Draws the text selection for the specified page. Should be called after calling AnnotationManager's drawAnnotations function if the selection should still be shown.
Parameters:
Name Type Description
pageNumber number The page number to draw the selection on

getActiveSearchResult()

Gets the currently active search result
Returns:
SearchResult CoreControls.DocumentViewer.SearchResult
Type
object

getAnnotationHistoryManager()

Returns the AnnotationHistoryManager used by this DocumentViewer
Returns:
an instance of AnnotationHistoryManager
Type
AnnotationHistoryManager

getAnnotationManager()

Returns the AnnotationManager used by this DocumentViewer
Returns:
an instance of AnnotationManager
Type
AnnotationManager

getAnnotationsLoadedPromise()

Gets a promise that resolves when the annotations in the current document have all been loaded
Returns:
Promise that resolves when the annotations in the current document have loaded.
Type
Promise.<any>

getColorSeparationsAtPoint(pageNumber, x, y)

Gets the color separation values for the specified point. The x and y values should be in page coordinates.
Parameters:
Name Type Description
pageNumber number The page number of the point
x number The x value of the point
y number The y value of the point
Returns:
A list of objects which each have the name of the separation and the saturation percentage of the color at the point [{ name, value }, ...]
Type
Array.<any>

getCompleteRotation(pageNumber)

Returns the complete rotation of the page including the document's rotation.
Parameters:
Name Type Description
pageNumber number The page number to get that page's rotation
Returns:
The current complete rotation.
Type
CoreControls.PageRotation

getCurrentPage()

Returns the current page number.
Returns:
The current 1-indexed page number.
Type
number

getDisplayModeManager()

Returns the DisplayModeManager used by this DocumentViewer
Returns:
an instance of DisplayModeManager
Type
DisplayModeManager

getDocument()

Returns the Document that is currently being displayed by the viewer.
Returns:
returns the current document.
Type
CoreControls.Document

getExactViewportRegionRect(pageNumber)

Returns the exact viewport rendering region if viewport rendering is enabled.
Parameters:
Name Type Description
pageNumber number The page number
Returns:
returns the current viewport rendering region
Type
object

getFitMode()

Returns the current fit mode.
Returns:
The current fit mode.
Type
CoreControls.DocumentViewer.FitMode

getMargin()

Returns a pixel value, representing the left, right, top and bottom margins.
Returns:
The margin value.
Type
number

getPageCount()

Returns the number of pages in a document.
Returns:
The number of the pages in the current document.
Type
number

getPageHeight(pageNumber)

Get the current height of the specified page, taking into account rotation.
Parameters:
Name Type Description
pageNumber number The page number
Returns:
The height of the page
Type
number

getPageRotations()

Gets the individual page rotations of the document. Only returns pages that have been rotated individually.
Returns:
An object with keys that are page indexes (1-indexed) and values that are rotation values.
Type
object

getPageSearchResults( [pageNumber])

Get results of the current search
Parameters:
Name Type Argument Description
pageNumber number <optional>
page number indicating to return the search hits from a specific page. If it's not given, the function will return search hits from all document pages.
Returns:
SearchResult array CoreControls.DocumentViewer.SearchResult
Type
object

getPageWidth(pageNumber)

Get the current width of the specified page, taking into account rotation.
Parameters:
Name Type Description
pageNumber number The page number
Returns:
The width of the page
Type
number

getPageZoom(pageNumber)

Get the zoom value for a particular page.
Parameters:
Name Type Description
pageNumber number The page number.
Returns:
Returns page's zoom value
Type
number

getRightToLeftPages()

Returns the page rendering order.
Returns:
The current page rendering order.
Type
boolean

getRotation( [pageNumber])

Returns the current viewing rotation.
Parameters:
Name Type Argument Description
pageNumber number <optional>
Optionally pass the page number to get the specific page's rotation
Returns:
The current viewing rotation.
Type
CoreControls.PageRotation
Example
PageRotation['E_0'] = 0 (0 degress) <br/>
PageRotation['E_90'] = 1 (90 degress) <br/>
PageRotation['E_180'] = 2 (180 degress) <br/>
PageRotation['E_270'] = 3 (270 degress) <br/>

getScrollViewElement()

Gets the scrollview element that is being used by DocumentViewer
Returns:
The scrollview DOM element that DocumentViewer appends pages
Type
Element

getSelectedText( [pageNumber])

Returns the text selected by text selection tool or search.
Parameters:
Name Type Argument Description
pageNumber number <optional>
Optionally pass the 1-indexed page number
Returns:
Selected text.
Type
string

getSelectedTextQuads( [pageNumber])

Returns the quads of the text selected by text selection tool or search.
Parameters:
Name Type Argument Description
pageNumber number <optional>
Optionally pass the 1-indexed page number
Returns:
Selected text quads.
Type
object

getTextLineInformation(pageNumber, point)

Returns information about the line of text that the point is found within
Parameters:
Name Type Description
pageNumber The page number where the line information should be retrieved from
point The point within the text line
Returns:
A promise that resolves with the text of the line, and the bounding box information pertaining to the line
Type
Promise.<CoreControls.DocumentViewer.TextLineInformation>

getTool(Name)

Returns a specific tool from the tool mode map.
Parameters:
Name Type Description
Name string | Tools.ToolNames of the tool. eg 'AnnotationEdit'
Returns:
The tool mode map object.
Type
Tools.Tool

getToolMode()

Returns the current tool.
Returns:
The current tool.
Type
Tools.Tool

getToolModeMap()

Returns the tool mode map object.
Returns:
The tool mode map object.
Type
object

getViewerElement()

Gets the viewer element that is being used by DocumentViewer
Returns:
The viewer DOM element that DocumentViewer appends pages
Type
Element

getViewportRegionRect(pageNumber)

Returns the current viewport rendering region if viewport rendering is enabled.
Parameters:
Name Type Description
pageNumber number The page number
Returns:
returns the current viewport rendering region
Type
object

getWatermark()

Gets the watermark options that had been previously set.
Returns:
Returns a promise containing the watermark options.
Type
Promise.<object>

getZoom()

Returns the current zoom level
Returns:
The current zoom level.
Type
number

isAutomaticLinkingEnabled()

Returns whether add automatic link is enabled.
Returns:
Whether add automatic link is enabled.
Type
boolean

isInViewportRenderMode()

Returns a boolean to denote if viewer is in viewport rendering mode
Returns:
the boolean to denote if in viewport render mode
Type
boolean

loadAsync(partRetriever, options)

Initialize the viewer and load a .xod document into the viewer.
Parameters:
Name Type Description
partRetriever PartRetrievers.HttpPartRetriever | PartRetrievers.LocalPartRetriever | PartRetrievers.StreamingPartRetriever An instance of PartRetriever.
options object An object that can contain the following optional parameters
Properties
Name Type Argument Description
type string <optional>
The type of document being loaded. Values are xod, pdf, office, blackbox. Default is xod.
docId string <optional>
An optional unique identifier for the document, used for offline mode
onError function <optional>
A callback of the form function(err) which will be called when a loading error occurs.
workerTransportPromise Promise.<void> <optional>
Required for PDF viewing. A promise that will be resolved when a worker transport has been initialized. This can be created by calling CoreControls.initializeWorkerTransport
getPassword function <optional>
An method of the form function(callback) where callback is of the form function(password). getPassword will be called when a password is required to load a PDF document and should call the callback with the retrieved password.
extension string <optional>
An field used to specify the type of file being read. This is only relevant for PDF viewing and at the moment only works for certain image formats and .pdf
licenseKey string <optional>
The license key to use. Only necessary for client side and WebViewer Server rendering.

loadDocument(source [, options])

Initialize the viewer and load the given file into the viewer.
Parameters:
Name Type Argument Description
source string | File | ArrayBuffer | Blob | CoreControls.Document | PDFNet.PDFDoc Source parameter, path/url to document or File.
options object <optional>
An object that can contain the following optional parameters.
Properties
Name Type Argument Description
l string <optional>
The license key for viewing PDF or Office files (PDF/Office only).
docId string <optional>
An unique identifier for the document, used for offline mode.
onLoadingProgress function <optional>
A callback function for loading progress, function signature function(percent) {}.
onError function <optional>
A callback function that will be called when error occurs in the process of loading a document. function signature function(e) {}
workerTransportPromise Promise.<any> <optional>
The workerTransportPromise that should be used to load the document.
password string | function <optional>
A password string or a function of the form function(callback) where callback is of the form function(password). This 'password' function will be called when a password is required to load a PDF document and should call the callback with the retrieved password.
filename string <optional>
A filename that is used for the downloaded file, and for determining the extension when options.extension isn't used.
extension string <optional>
Used for specifying the extension of the document to be loaded. This is necessary if the URL/path does not contain the file extension or if you're loading a Blob/File.
customHeaders object <optional>
An object containing custom HTTP headers to use when retrieving the document from the specified url. For example: {'Authorization' : 'Basic dXNlcm5hbWU6cGFzc3dvcmQ='}.
useDownloader boolean <optional>
A boolean indicating whether Downloader should be used on urls (PDF only). https://www.pdftron.com/documentation/web/guides/usedownloader-option/.
withCredentials boolean <optional>
Whether to set the withCredentials property on the XMLHttpRequest.
pageSizes Array.<object> <optional>
An array of objects in the shape of { width: number, height: number }. Used to determine the page sizes when loading an image file.
backendType string <optional>
A string representing the "backend type" for rendering PDF documents. Pass "ems" to force the use of the ASM.js/WebAssembly worker and "wasm-threads" for threaded WebAssembly.
xodOptions object <optional>
An object that contains the options for a XOD document.
Properties
Name Type Argument Description
decrypt boolean <optional>
Function to be called to decrypt a part of the XOD file. For default XOD AES encryption pass CoreControls.Encryption.decrypt.
decryptOptions boolean <optional>
An object with options for the decryption e.g. {p: "pass", type: "aes"} where is p is the password.
streaming boolean <optional>
A boolean indicating whether to use http or streaming PartRetriever, it is recommended to keep streaming false for better performance. https://www.pdftron.com/documentation/web/guides/streaming-option.
azureWorkaround boolean <optional>
Whether or not to workaround the issue of Azure not accepting range requests of a certain type. Enabling the workaround will add an extra HTTP request of overhead but will still allow documents to be loaded from other locations.
startOffline boolean <optional>
Whether to start loading the document in offline mode or not. This can be set to true if the document had previously been saved to an offline database using WebViewer APIs. You'll need to use this option to load from a completely offline state.
pdftronServer string <optional>
A URL to the WebViewer server drop-in backend https://www.pdftron.com/documentation/web/guides/wv-server-deployment.
fallbackToClientSide boolean <optional>
A boolean indicating whether to fall back to client side rendering when WebViewer server fails
cacheKey string <optional>
A key that will be used for caching the document on WebViewer Server.
forceClientSideInit boolean <optional>
If set to true then when loading a document using WebViewer Server the document will always switch to client only rendering allowing page manipulation and the full API to be used.
loadAsPDF boolean <optional>
If set to true then this will convert any office file passed in into a PDF document
type string <optional>
A custom document type. If set then the document type is not determined from the file extension.
customDocParams object <optional>
An object used to pass properties down to a custom document type.
Returns:
A promise that resolves when the document is finished loading
Type
Promise.<void>

off( [type] [, fn])

Remove a handler of the given event name
Parameters:
Name Type Argument Description
type string | number <optional>
The name of the event to remove the handler of. If type is undefined, all the handlers of the object will be removed
fn function <optional>
The handler associated with this event to be removed. If fn is undefined, all the handlers of the given event name will be removed
Inherited From:
Returns:
Returns the object that 'off' is being called on
Type
object
Example
annotManager.off();
annotManager.off('annotationChanged');
annotManager.off('annotationChanged', fn);

on(type, fn)

Add a handler to the given event name
Parameters:
Name Type Description
type string | number The name of the event to listen to
fn function The handler to be called when the event is triggered
Inherited From:
Returns:
Returns the object that 'on' is being called on
Type
object
Example
annotManager.on('annotationChanged', (annotations, action) => {
  ...
});

one(type, fn)

Same as 'on' except the handler will be called only once
Parameters:
Name Type Description
type string | number The name of the event to listen to
fn function The handler to be called when the event is triggered
Inherited From:
Returns:
Returns the object that 'one' is being called on
Type
object
Example
annotManager.one('annotationChanged', (annotations, action) => {
 ...
});

recalculateLayout(pagesToRecalculate)

Request a recalculation of page layout and rerender all pages. For use when modifying the underlying Document without using the provided page modification functions (cropPages, rotatePages...)
Parameters:
Name Type Description
pagesToRecalculate Array.<number> An array of page numbers (1-indexed) that should be recalculated

refreshAll()

Invalidates the rendering cache for all pages and removes embedded thumbnails for viewer optimized PDF

refreshAllAndClear()

Invalidates the rendering cache for all pages, this not exposed function.

refreshPage(pageNumber)

Invalidates the rendering cache for the specified page
Parameters:
Name Type Description
pageNumber number The page number of the page (1-indexed)

removeContent(removeData, rotationChanged, isZoomChanged)

Removes all the page content from the DOM. Also clear the cache if the zoom or rotation has changed.
Parameters:
Name Type Description
removeData boolean Whether or not to remove all event handlers and data on the elements
rotationChanged boolean
isZoomChanged boolean

rotateClockwise( [pageNumber])

Rotates all pages in the currently displayed document clockwise by 90 degrees.
Parameters:
Name Type Argument Description
pageNumber number <optional>
Optionally pass the page number to rotate only a specific page

rotateCounterClockwise( [pageNumber])

Rotates all pages in the currently displayed document counter-clockwise by 90 degrees.
Parameters:
Name Type Argument Description
pageNumber number <optional>
Optionally pass the page number to rotate only a specific page

scrollViewUpdated()

This function must be called after modifying the scroll view element's dimensions or properties. The scroll view is the element returned from docViewer.getScrollViewElement()

select(pt1, pt2)

Selects the text content of the document given two page coordinates.
Parameters:
Name Type Description
pt1 Starting page coordinate. Requires properties x, y and pageIndex.
pt2 Ending page coordinate. Requires properties x, y and pageIndex.

setActiveSearchResult(result)

Sets the active search result, causing it to be displayed as a different color and visible on the screen.
Parameters:
Name Type Description
result object The result of a search, CoreControls.DocumentViewer.SearchResult. Returned by onResult in CoreControls.DocumentViewer#textSearchInit.

setAnnotationImportOptions(options)

Set the options that are used when importing annotations from a document asynchronously. These are the options that will be passed to AnnotationManager.importAnnotations.
Parameters:
Name Type Description
options object The options for importing
Properties
Name Type Description
batchSize number The number of annotations to import in each batch
batchDelay number The amount of time in milliseconds to delay between importing each batch

setCurrentPage(pageNumber)

Sets the current page. Updates the current page and jumps to it.
Parameters:
Name Type Description
pageNumber number The page number to jump to.

setDocumentXFDFRetriever(retriever)

Sets the XFDF retriever that will be called when a document is being loaded. The XFDF returned from the retriever will be merged into the document. It is recommended to use this function instead of annotManager.importAnnotations if you are loading XFDF from your server so that you don't need to wait for the annotationsLoaded event to be triggered. setDocumentXFDFRetriever will ensure that the annotation data is merged at the right time and as early as possible.
Parameters:
Name Type Description
retriever CoreControls.DocumentViewer.DocumentXFDFRetriever | null A retriever function that returns a Promise which should resolve to the XFDF string that is going to merged into the document
Returns:
A promise that resolves when the retriever has been set
Type
Promise.<void>
Example
instance.docViewer.setDocumentXFDFRetriever(async (documentId) => {
  const documentXFDFString = await fetchDocumentXFDFFromServer(documentId);
  return documentXFDFString;
})

setEnableAutomaticLinking(enable)

Sets whether automatic linking should be enabled. If enabled then any URLs detected in the document text will automatically be linked.
Parameters:
Name Type Description
enable boolean Whether to enable automatic linking.

setEnableStylusMode(enable)

Sets if all the annotation tools are in the stylus annotating mode. When in this mode, finger movements will scroll the document and using a stylus device will annotate the document.
Parameters:
Name Type Description
enable boolean a boolean indicating whether stylus annotating mode should be used

setEnableStylusMode()

Returns whether stylus annotating mode is enabled.
Returns:
Returns whether stylus annotating mode is enabled
Type
boolean

setFitMode(fitMode)

Sets how the document will scale to fit the size of the scrollviewer's viewport. Also re-renders content to the appropriate zoom level. Only renders if a document has been loaded.
Parameters:
Name Type Description
fitMode DocumentViewer.FitMode

setInternalAnnotationsTransform(handler)

Allows you to transform (or replace) the internal annotations of the document. Note that to handle annotations using PDFNetJS without useDownloader: false you will also want to call setPagesUpdatedInternalAnnotationsTransform
Parameters:
Name Type Description
handler function A handler function that takes annotation data as the first parameter and a callback that is called when the transformed data is ready as the second parameter

setLoadAnnotationsFromVisiblePages(val)

Sets whether annotations should only be loaded from the visible pages and removed when a page is no longer visible. Note that when enabling this option only annotations on the visible pages will be exported or included in the downloaded document
Parameters:
Name Type Description
val boolean Whether the option should be enabled or not

setMargin(margin)

Set the pixel value to use for the left, right, top and bottom margins.
Parameters:
Name Type Description
margin number The margin value to set.

setOptions(options)

Sets specific DocumentViewer options.
Parameters:
Name Type Description
options object An options object, currently valid options are enableAnnotations and annotMode

setPageRotations(rotations)

Sets the individual page rotations of multiple pages at once. Pages that aren't specified will use the default document rotation.
Parameters:
Name Type Description
rotations object An object with keys that are page indexes (1-indexed) and values that are rotation values. Rotations should be specified as {CoreControls.PageRotation}s

setPagesUpdatedInternalAnnotationsTransform(handler)

Allows you to transform (or replace) the internal annotations of the document when pages receive an update event. This includes when using PDFNetJS with downloader enabled (default) on a linearized document. For completeness you will also want to call setInternalAnnotationsTransform.
Parameters:
Name Type Description
handler function A handler function that takes annotation data as the first parameter, an array of updated page numbers as a second parameter and a callback that is called when the transformed data is ready as a third parameter

setPageVisibilityCallback(callback)

Sets the callback function that will be called when a page is newly visible in the viewer.
Parameters:
Name Type Description
callback function A function that takes in a page number indicating the page that is now visible

setPageZoom(pageNumber, zoom)

Sets the zoom for a particular page. Should be followed by a call to updateView to actually render the page.
Parameters:
Name Type Description
pageNumber number The page number.
zoom number Zoom value for page.

setRightToLeftPages(rightToLeftPages)

Sets the page rendering order.
Parameters:
Name Type Description
rightToLeftPages boolean Whether the new page rendering order should be right to left or not.

setRotation(pageRotation [, pageNumber])

Sets the current viewing rotation.
Parameters:
Name Type Argument Description
pageRotation CoreControls.PageRotation desired viewing rotation.
pageNumber number <optional>
Optionally pass the page number to set the specific page's rotation

setScrollViewElement(scrollViewElement)

Sets the scrollview element that DocumentViewer will append rendered pages to.
Parameters:
Name Type Description
scrollViewElement Element The scrollview DOM element to be used

setSearchHighlightColors(colorOptions)

Sets the color to use when highlighting text from searching.
Parameters:
Name Type Description
colorOptions object An object with searchResult or activeSearchResult properties set as a color eg 'rgba(0, 0, 200, 0.5)'
Example
docViewer.setSearchHighlightColors({
  searchResult: 'rgba(255, 0, 0, 0.5)',
  activeSearchResult: 'rgba(0, 255, 0, 0.5)'
});

setTextHighlightColor(color)

Sets the color to use when highlighting text from text selection.
Parameters:
Name Type Description
color string The color to set. eg 'rgba(0, 0, 200, 0.3)'

setToolMode(tool)

Sets the tool mode. Also removes selection caused by text selection or search.
Parameters:
Name Type Description
tool Tools.Tool An instance of the toolmode

setViewerElement(viewerElement)

Sets the viewer element that DocumentViewer will append rendered pages to.
Parameters:
Name Type Description
viewerElement Element The viewer DOM element to be used

setViewportRenderMode(val)

Sets whether viewport rendering mode should be used
Parameters:
Name Type Description
val boolean Whether viewport rendering mode should be used or not

setWatermark(options)

Sets watermark to be added to documents. Instead of an options object you can also pass a Promise that resolves with the watermark options object. If the document hasn't been loaded yet then DocumentViewer will wait to finish loading it until the watermark options are ready.
Parameters:
Name Type Description
options object Object that contains style/content of the watermark
Properties
Name Type Argument Default Description
diagonal object <optional>
Settings for a diagonal watermark
Properties
Name Type Argument Default Description
text string <optional>
The text content to be rendered as a diagonal watermark
fontSize number <optional>
20 The font size of the text, measured in pixels (px)
fontFamily string <optional>
'sans-serif' The font type
color string <optional>
'black' The color of the text
opacity number <optional>
100 The percentage of opacity for the watermark
header object <optional>
Settings for a header watermark
Properties
Name Type Argument Default Description
left string <optional>
The text content to be rendered at the left side of the header
center string <optional>
The text content to be rendered at the center of the header
right string <optional>
The text content to be rendered at the right side of the header
fontSize number <optional>
20 The font size of the text, measured in pixels (px)
fontFamily string <optional>
'sans-serif' The font type
color string <optional>
'black' The color of the text
opacity number <optional>
100 The percentage of opacity for the watermark
footer object <optional>
Settings for a footer watermark
Properties
Name Type Argument Default Description
left string <optional>
The text content to be rendered at the left side of the footer
center string <optional>
The text content to be rendered at the center of the footer
right string <optional>
The text content to be rendered at the right side of the footer
fontSize number <optional>
20 The font size of the text, measured in pixels (px)
fontFamily string <optional>
'sans-serif' The font type
color string <optional>
'black' The color of the text
opacity number <optional>
100 The percentage of opacity for the watermark
custom CoreControls.DocumentViewer.CustomWatermarkCallback <optional>
Function that is invoked for each page, to fully customize which page(s) have a watermark render, and how they should be rendered.
shouldDrawOverAnnotations boolean <optional>
false Toggles if the watermark should be drawn over annotations
Example
docViewer.setWatermark({
  diagonal: {
    text: (string),
    fontSize: (number || 20),
    fontFamily: (string || 'sans-serif'),
    color: (string || 'black'),
    opacity: (number || 100)
  },
  header: {
    left: (string),
    center: (string),
    right: (string),
    fontSize: (number || 20),
    fontFamily: (string || 'sans-serif'),
    color: (string || 'black'),
    opacity: (number || 100)
  },
  footer: {
    left: (string)
    center: (string),
    right: (string),
    fontSize: (number || 20),
    fontFamily: (string || 'sans-serif'),
    color: (string || 'black'),
    opacity: (number || 100),
  },
  custom: (function(ctx, pageIndex, pageWidth, pageHeight)),
  shouldDrawOverAnnotations: (boolean || false)
});

snapToNearest(pageNumber, x, y [, mode])

Returns the path coordinate within the page that is closest to the queried point.
Parameters:
Name Type Argument Description
pageNumber number The page number the point is on
x number The x position to calculate the snap point from
y number The y position to calculate the snap point from
mode number <optional>
Enum for an optional snapping mode for the snapping
Returns:
A promise that resolves to an object with x and y properties representing the nearest path point
Type
Promise.<any>

stopPageRender(pageNumber)

Stops the rendering of the specified page.
Parameters:
Name Type Description
pageNumber number The number of the page who's rendering should be stopped.

textSearchInit(pattern, mode [, searchOptions])

Searches for a particular text string on the currently displayed Document, starting on the current page unless otherwise specified.
Parameters:
Name Type Argument Description
pattern string The text to search for.
mode number The options for search, controlling options such as case sensitivity and search direction.
searchOptions object <optional>
An object that can contain the following optional parameters
Properties
Name Type Argument Description
fullSearch boolean <optional>
If true, a search of the entire document will be performed. Otherwise, a single search will be performed.
onResult function <optional>
(result) The callback function that is called when the search returns a result.
onPageEnd function <optional>
(result) The callback function that is called when reaching the end of the page (if using page_stop mode).
onDocumentEnd function <optional>
() The callback function that is called when reaching the end of the document.
onError function <optional>
(result) The callback function that is called when search failed or regex has syntax error.
startPage number <optional>
Page to start the search on (1-indexed).
endPage number <optional>
Page to end the search on inclusively (1-indexed). The search may complete when the search term is found, when the entire document has been searched, and, depending on the search options, at the end of every page. Parameter result: DocumentViewer.SearchResults.
See:
  • CoreControls.DocumentViewer#SearchMode

trigger(type [, data])

Calls the handlers of the event name with given data
Parameters:
Name Type Argument Description
type string | number event name of which the handlers will be called.
data * <optional>
data that will be passed to the handlers. If data is an array, it will be spread and then passed to the handlers
Inherited From:
Returns:
Returns the object that 'trigger' is being called on
Type
object
Example
annotManager.trigger('annotationChanged');
annotManager.trigger('annotationChanged', [[annotation], 'add', {}]);

Updates old xod (version <= 1.2) link annotations in the annotation manager
Parameters:
Name Type Description
pageNumber number The 1-indexed page number to update

updateView(visiblePages, currentPageNumber)

Removes previously drawn pages that are no longer visible and draws pages that are visible and have not been drawn. If visiblePages are provided then those pages are rendered otherwise visiblePages are calculated depending on where the DIV elements for the pages are located.
Parameters:
Name Type Description
visiblePages Array.<number> An array of integers representing the pages to render.
currentPageNumber number The number of the page that is currently visible in the viewer.

updateVisiblePages(visiblePages)

Notifies the document viewer that the visible pages have changed but does not draw any pages.
Parameters:
Name Type Description
visiblePages Array.<number>

zoomTo(zoom [, x] [, y])

Adjusts the viewer's zoom factor, and positions the point (x,y) at the upper left corner of the viewer. Only renders if a document has been loaded.
Parameters:
Name Type Argument Description
zoom number Zoom value.
x number <optional>
Horizontal position to scroll to.
y number <optional>
Vertical position to scroll to.

zoomToMouse(zoom, offsetX, offsetY)

Adjusts the viewer's zoom factor and positions the point on the document under the mouse at the same position after zooming in.
Parameters:
Name Type Description
zoom number Zoom value
offsetX number The x offset from the mouse position to the viewer's position (e.g. taking into account toolbars)
offsetY number The y offset from the mouse position to the viewer's position (e.g. taking into side panels)

Type Definitions


CustomWatermarkCallback(ctx, pageIndex, pageWidth, pageHeight)

Parameters:
Name Type Description
ctx CanvasRenderingContext2D The Canvas Context that determines how the watermark will be rendered. Edit the text styles attributes to change the rendering styling.
pageIndex number The index of the current page
pageWidth number The width of the current page
pageHeight number The height of the current page

DocumentXFDFRetriever(docId)

Parameters:
Name Type Description
docId string the id of the document that is being loaded
Returns:
A promise that resolves to an XFDF string, or an array of XFDF commands
Type
Promise.<(string|Array.<string>)>

TextLineInformation

Type:
  • object
Properties:
Name Type Description
text string The text of the line
boundingBox CoreControls.Math.Rect The coordinate information of the bounding box of the line

Events


activeSearchResultChanged

Triggered when the active search result has changed
Parameters:
Name Type Description
result object The new active search result, CoreControls.DocumentViewer.SearchResult.

annotationsLoaded

Triggered when all the annotations embedded in the document have been loaded

beforeDocumentLoaded

Triggered just before the document has been loaded into the viewer

beginRendering

Triggered when DocumentViewer starts rendering pages

changePage

Triggered when the page should be changed. Only fired when using a non-scrollable custom display mode.
Parameters:
Name Type Description
pageNum number The 1-indexed page number

click

Triggered for the click event in the DocumentViewer's viewing area
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

dblClick

Triggered for the dblClick event in the DocumentViewer's viewing area
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

displayModeUpdated

Triggered when the display mode is updated

displayPageLocation

Triggered when a page location should be displayed
Parameters:
Name Type Description
pageNum number The 1-indexed page number
verticalOffset number The offset from the top of the page
horizontalOffset number The offset from the left of the page

documentLoaded

Triggered when a new document has been loaded

documentUnloaded

Triggered when the current document has been closed and unloaded

finishedRendering

Triggered when DocumentViewer finishes rendering pages

fitModeUpdated

Triggered when the fit mode has changed
Parameters:
Name Type Description
fitMode object The fit mode that has been changed to e.g. docViewer.FitMode.FitWidth

keyDown

Triggered for the keyDown event in the DocumentViewer's viewing area
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

keyUp

Triggered for the keyUp event in the DocumentViewer's viewing area
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

layoutChanged

Triggered when the layout has changed because pages have permanently been added, removed, moved or changed in some other way.
Parameters:
Name Type Description
changes object An object with keys added, removed, moved and contentChanged, indicating which pages have changed

mouseEnter

Triggered for the mouseEnter event in the DocumentViewer's viewing area
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

mouseLeave

Triggered for the mouseLeave event in the DocumentViewer's viewing area
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

mouseLeftDown

Triggered for the mouseLeftButtonDown event in the DocumentViewer's viewing area Attach like docViewer.on('mouseLeftDown', callback)
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

mouseLeftUp

Triggered for the mouseLeftButtonUp event in the DocumentViewer's viewing area
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

mouseMove

Triggered for the mouseMove event in the DocumentViewer's viewing area
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

mouseRightDown

Triggered for the mouseRightButtonDown event in the DocumentViewer's viewing area
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

mouseRightUp

Triggered for the mouseRightButtonUp event in the DocumentViewer's viewing area
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

notify

Triggered when there is a notification relating to searching or annotation permissions.
Parameters:
Name Type Description
type string The type of notification that has occurred

pageComplete

Triggered when a page has been completely rendered.
Parameters:
Name Type Description
pageNum number The 1-indexed page number
canvas HTMLCanvasElement The canvas for the page

pageNumberUpdated

Triggered when the page number is updated
Parameters:
Name Type Description
pageNumber number The new page number (1-indexed)

rotationUpdated

Triggered when the page rotation has changed
Parameters:
Name Type Argument Description
rotation CoreControls.PageRotation The new viewing rotation.
pageNumber number <optional>
Optionally the specific page number that had its rotation changed

searchInProgress

Triggered when a search starts or ends. When CoreControls.DocumentViewer#clearSearchResults is executed searchInProgress event is triggered with both inProgress and isFullSearch arguments to be undefined. This can be used to differentiate the search that hasn’t been started versus the search that was done.
Parameters:
Name Type Description
inProgress boolean Whether a search is in progress or not
isFullSearch boolean Whether this is a full text search or not

searchResultsChanged

Triggered when the search results list has changed
Parameters:
Name Type Description
results Array.<object> The new search results, CoreControls.DocumentViewer.SearchResult.

tap

Triggered when there is a tap in the DocumentViewer's viewing area. Taps are defined as a mouse down and up within a short time period and within a short distance.a
Parameters:
Name Type Description
nativeEvt object Event object of the native JavaScript event

textSelected

Triggered when the selected text has changed
Parameters:
Name Type Description
quads Array.<CoreControls.Math.Quad> An array of bounding box quads of the selected text
text string The selected text
pageNumber number The page number that the text was selected on

toolModeUpdated

Triggered when the tool mode has changed
Parameters:
Name Type Description
toolModeClass object The tool object that has been changed to.

toolUpdated

Triggered when the tool styles or tool name have changed
Parameters:
Name Type Description
toolModeClass object The tool object that has been changed.

zoomUpdated

Triggered when the zoom level has been updated
Parameters:
Name Type Description
zoom number The new zoom level of the viewer