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:
-
<static> FitMode
-
Contains a list of available fit modes for the DocumentViewer.
Properties:
Name Type Description FitWidthfunction Zoom level is constrained such that the current page's width will exactly fill the available space. FitPagefunction Zoom level is constrained such that the current page's width or height will exactly fill the available space. Zoomfunction Zoom level is not constrained. -
<static> SearchResults
-
The code indicating the reason that the search process concluded.
Properties:
Name Type Description ambientStrstring The text surrounding the result string. resultStrstring The found text. resultStrStartnumber The index in ambient string where the result string starts. resultStrEndnumber The index in ambient string where the result string end. pageNumnumber The page number which the search was conducted on. resultCodenumber The reason the search completed. quadsobject A list of Quads, representing the bounding box(es) of the found text. Useful for highlighting the text.
Methods
-
addEventListener(type, fn [, options])
-
Add a handler to the given event name
Parameters:
Name Type Argument Description typestring | number The name of the event to listen to fnfunction The handler to be called when the event is triggered optionsobject <optional>
Optional options object for addEventListener Properties
Name Type Description onceboolean If true then the handler will be called only once - Inherited From:
Returns:
Returns the object that 'addEventListener' is being called on- Type
- object
Example
myObject.addEventListener('eventName', (eventParameter1, eventParameter2) => { ... }); -
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.
-
disableAnnotations()
-
Disable annotations. Annotations in the document will not be visible.
-
disableArrowKeyNavigation()
-
Disable using the left/right arrow keys to switch pages.
-
disableAutomaticLinking()
-
Disable automatic linking. If disabled then any URLs detected in the document text will not automatically be linked.
-
disableGrayscaleAnnotationsMode()
-
Disable viewing annotations in grayscale
-
disableGrayscaleMode()
-
Disable viewing document in Grayscale
-
disableLoadingAnnotationsFromVisiblePages()
-
If loading annotations from visible pages was previously enabled then calling this function will switch back to the default behavior.
-
disableReadOnlyMode()
-
Disables read-only mode in the viewer.
-
disableRightToLeftPageRendering()
-
Disable right to left page rendering order.
-
disableStylusMode()
-
Disables the stylus annotating mode for all annotation tools.
-
disableViewportRenderMode()
-
Disables viewport rendering mode
-
displayAdditionalSearchResult(result)
-
Displays the new search result without clearing previous results
Parameters:
Name Type Description resultobject The result of a search, Core.DocumentViewer.SearchResult Returned by onResult in Core.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 resultsArray.<object> An array of search results Core.DocumentViewer.SearchResult. Returned by onResult in Core.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. If the bookmark is a JavaScript action then it executes the action.
Parameters:
Name Type Description bookmarkCore.Bookmark A bookmark that specifies the location to go to. Returned by Core.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://docs.apryse.com/documentation/web/guides/coordinates/#viewer-page-coordinates for more details
Parameters:
Name Type Argument Description pageNumbernumber The page number the location is on horizontalPositionnumber The horizontal position from the x-axis origin of the page (in viewer page coordinates) verticalPostionnumber The vertical position from the y-axis of the page (in viewer page coordinates) doNotJumpIfInViewboolean <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 resultobject The result of a search, Core.DocumentViewer.SearchResult. Returned by onResult in Core.DocumentViewer#textSearchInit. jumpfunction <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 pageNumbernumber The page number to draw the selection on -
enableAnnotations()
-
Enable annotations. Any annotations in the document will be visible.
-
enableArrowKeyNavigation()
-
Enable using the left/right arrow keys to switch pages.
-
enableAutomaticLinking()
-
Enable automatic linking. If enabled then any URLs detected in the document text will automatically be linked.
-
enableGrayscaleAnnotationsMode()
-
Enable viewing annotations in grayscale
-
enableGrayscaleMode()
-
Enable viewing document in Grayscale
-
enableLoadingAnnotationsFromVisiblePages()
-
Enable annotations to 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
-
enableReadOnlyMode()
-
Enables read-only mode in the viewer. In this mode no page manipulation features can be done from thumbnail panel of UI.
-
enableRightToLeftPageRendering()
-
Enable the right to left page rendering order.
-
enableStylusMode()
-
Puts all annotation tools in the stylus annotating mode. When in this mode, finger movements will scroll the document and using a stylus device will annotate the document.
-
enableViewportRenderMode()
-
Enables viewport rendering mode. This only renders the part of the page that is visible within the viewport.
-
getActiveSearchResult()
-
Gets the currently active search result
Returns:
SearchResult Core.DocumentViewer.SearchResult- Type
- object
-
getAnnotationHistoryManager()
-
Returns the AnnotationHistoryManager used by this DocumentViewer
Returns:
An instance of AnnotationHistoryManager -
getAnnotationManager()
-
Returns the AnnotationManager used by this DocumentViewer
Returns:
An instance of 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 pageNumbernumber The page number of the point xnumber The x value of the point ynumber 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 pageNumbernumber The page number to get that page's rotation Returns:
The current complete rotation.- Type
- Core.PageRotation
-
getContentEditManager()
-
Returns the ContentEditManager used by this DocumentViewer
Returns:
An instance of ContentEditManager -
getCurrentPage()
-
Returns the current page number.
Returns:
The current 1-indexed page number.- Type
- number
-
getCurrentSearchMode()
-
Returns the current search mode, controlling options such as case sensitivity and regex flags.
Returns:
currentMode Core.Search.Mode- Type
- number
-
getDisplayModeManager()
-
Returns the DisplayModeManager used by this DocumentViewer
Returns:
An instance of DisplayModeManager -
getDocument()
-
Returns the Document that is currently being displayed by the viewer.
Returns:
returns the current document.- Type
- Core.Document
-
getExactViewportRegionRect(pageNumber)
-
Returns the exact viewport rendering region if viewport rendering is enabled.
Parameters:
Name Type Description pageNumbernumber The page number Returns:
returns the current viewport rendering region- Type
- object
-
getFitMode()
-
Returns the current fit mode.
Returns:
The current fit mode. -
getMargin()
-
Returns a pixel value, representing the left, right, top and bottom margins.
Returns:
The margin value.- Type
- number
-
getMeasurementManager()
-
Returns the MeasurementManager used by this DocumentViewer
Returns:
An instance of MeasurementManager -
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 pageNumbernumber 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 pageNumbernumber <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 Core.DocumentViewer.SearchResult- Type
- object
-
getPageWidth(pageNumber)
-
Get the current width of the specified page, taking into account rotation.
Parameters:
Name Type Description pageNumbernumber 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 pageNumbernumber The page number. Returns:
Returns page's zoom value- Type
- number
-
getPDFCoordinatesFromMouseEvent(event)
-
Get the PDF coordinates of the current mouse event
Parameters:
Name Type Description eventMouseEvent A DOM mouse event. Returns:
Returns an object with the x and y PDF coordinates of the mouse event- Type
- object
-
getRotation( [pageNumber])
-
Returns the current viewing rotation.
Parameters:
Name Type Argument Description pageNumbernumber <optional>
Optionally pass the page number to get the specific page's rotation Returns:
The current viewing rotation.- Type
- Core.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 pageNumbernumber <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 pageNumbernumber <optional>
Optionally pass the 1-indexed page number Returns:
Selected text quads.- Type
- object
-
getTool(Name)
-
Returns a specific tool from the tool mode map.
Parameters:
Name Type Description Namestring | Core.Tools.ToolNames of the tool. eg 'AnnotationEdit' Returns:
The tool mode map object.- Type
- Core.Tools.Tool
-
getToolMode()
-
Returns the current tool.
Returns:
The current tool.- Type
- Core.Tools.Tool
-
getToolModeMap()
-
Returns the tool mode map object.
Returns:
The tool mode map object.- Type
- object
-
getViewerCoordinatesFromMouseEvent(event)
-
Get the viewer page coordinates of the current mouse event
Parameters:
Name Type Description eventMouseEvent A DOM mouse event. Returns:
Returns an object with the x and y viewer coordinates of the mouse event- 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 pageNumbernumber 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>
-
getZoomLevel()
-
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
-
isGrayscaleAnnotationsModeEnabled()
-
Returns whether grayscale annotations mode is enabled for viewing the document
Returns:
Whether grayscale annotation mode is enabled or not- Type
- boolean
-
isGrayscaleModeEnabled()
-
Returns whether grayscale mode is enabled for viewing the document
Returns:
Whether grayscale mode is enabled or not- 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
-
isRightToLeftPageRenderingEnabled()
-
Returns whether right to left page rendering is enabled.
Returns:
True if right to left page rendering is enabled, false otherwise.- Type
- boolean
-
loadDocument(src [, options])
-
Initialize the viewer and load the given file into the viewer.
Parameters:
Name Type Argument Description srcstring | File | ArrayBuffer | Blob | Core.Document | Core.PDFNet.PDFDoc Source parameter, path/url to document or File. optionsCore.LoadDocumentOptions <optional>
Load document options. Returns:
A promise that resolves when the document is finished loading- Type
- Promise.<void>
-
openURI(uri, isOpenInNewWindow)
-
Opens the given URI.
Parameters:
Name Type Description uristring the uri to open isOpenInNewWindowboolean whether to open the uri in a new window -
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 pagesToRecalculateArray.<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
-
refreshPage(pageNumber)
-
Invalidates the rendering cache for the specified page
Parameters:
Name Type Description pageNumbernumber 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 removeDataboolean Whether or not to remove all event handlers and data on the elements rotationChangedboolean isZoomChangedboolean -
removeEventListener( [type] [, fn])
-
Remove a handler of the given event name and namespace (if given) or with a function reference
Parameters:
Name Type Argument Description typestring | number <optional>
The name of the event to remove the handler of with an optional namespace. fnfunction <optional>
The handler associated with this event to be removed. If fn is undefined, all the handlers of the given event namespace will be removed. If you are not passing in this parameter then a namespace must be used with the event name. - Inherited From:
Returns:
Returns the object that 'removeEventListener' is being called on- Type
- object
Example
myObject.removeEventListener('eventName.namespace'); myObject.removeEventListener('eventName', fn); -
rotateClockwise( [pageNumber])
-
Rotates all pages in the currently displayed document clockwise by 90 degrees.
Parameters:
Name Type Argument Description pageNumbernumber <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 pageNumbernumber <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 pt1Starting page coordinate. Requires properties x, y and pageNumber. pt2Ending page coordinate. Requires properties x, y and pageNumber. -
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 resultobject The result of a search, Core.DocumentViewer.SearchResult. Returned by onResult in Core.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 optionsobject The options for importing Properties
Name Type Description batchSizenumber The number of annotations to import in each batch batchDelaynumber The amount of time in milliseconds to delay between importing each batch -
setBookmarkIconShortcutVisibility(isEnabled)
-
Show or hide the bookmark icon shortcuts on the top right corner of each page.
Parameters:
Name Type Description isEnabledboolean Whether to show or hide the bookmark icon shortcuts. -
setBookmarkShortcutToggleOffFunction(callback)
-
Accepts a function that runs when the bookmark icon shortcut on the top right corner of a page is toggled off.
Parameters:
Name Type Description callbackCore.DocumentViewer.onToggleOffBookmarkShortcut A callback function that takes 0-index based page number as parameter that removes a bookmark from the bookmark icon shortcut. -
setBookmarkShortcutToggleOnFunction(callback)
-
Accepts a function that runs when the bookmark icon shortcut on the top right corner of a page is toggled on.
Parameters:
Name Type Description callbackCore.DocumentViewer.onToggleOnBookmarkShortcut A callback function that takes 0-index based page number as parameter that adds a bookmark from the bookmark icon shortcut. -
setCurrentPage(pageNumber, isSmoothScroll)
-
Sets the current page. Updates the current page and jumps to it.
Parameters:
Name Type Description pageNumbernumber The page number to jump to. isSmoothScrollboolean If set to true, the viewer will scroll in a smooth way. -
setDefaultPageColor(color)
-
Sets default background color for pages, default is white.
Parameters:
Name Type Description colorstring Background color value -
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 retrieverCore.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.Core.documentViewer.setDocumentXFDFRetriever(async (documentId) => { const documentXFDFString = await fetchDocumentXFDFFromServer(documentId); return documentXFDFString; }) -
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 fitModeDocumentViewer.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 handlerfunction 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 -
setMargin(margin)
-
Set the pixel value to use for the left, right, top and bottom margins.
Parameters:
Name Type Description marginnumber The margin value to set. -
setOpenURIHandler(openURIHandler)
-
Sets the open URI handler.
Parameters:
Name Type Description openURIHandleropenURIHandler function that takes in a uri and a boolean indicating whether to open in a new window Returns:
- Type
- void
-
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 rotationsobject An object with keys that are page indexes (1-indexed) and values that are rotation values. Rotations should be specified as {Core.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 handlerfunction 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 callbackfunction 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 pageNumbernumber The page number. zoomnumber Zoom value for page. -
setRotation(pageRotation [, pageNumber])
-
Sets the current viewing rotation.
Parameters:
Name Type Argument Description pageRotationCore.PageRotation desired viewing rotation. pageNumbernumber <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 scrollViewElementElement The scrollview DOM element to be used -
setSearchHighlightColors(colorOptions)
-
Sets the color to use when highlighting text from searching.
Parameters:
Name Type Description colorOptionsobject 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)' }); -
setSearchPageBatchSize(searchBatchSize)
-
[PDF Document only] Set the number of pages to search at a time. Searching more pages at a time will speed up searching but decrease page rendering responsiveness while a search is ongoing. Default is 50.
Parameters:
Name Type Description searchBatchSizenumber The number of pages to search at a time -
setTextHighlightColor(color)
-
Sets the color to use when highlighting text from text selection.
Parameters:
Name Type Description colorstring 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 toolCore.Tools.Tool An instance of the toolmode -
setUserBookmarks(newBookmarks)
-
Set the user bookmarks from the left panel of UI.
Parameters:
Name Type Description newBookmarksArray.<number> An array of integers representing only the pages that are bookmarked from the left panel of UI. -
setViewerElement(viewerElement)
-
Sets the viewer element that DocumentViewer will append rendered pages to.
Parameters:
Name Type Description viewerElementElement The viewer DOM element to be used -
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 optionsobject Object that contains style/content of the watermark Properties
Name Type Argument Default Description diagonalobject <optional>
Settings for a diagonal watermark Properties
Name Type Argument Default Description textstring <optional>
The text content to be rendered as a diagonal watermark fontSizenumber <optional>
20 The font size of the text, measured in pixels (px) fontFamilystring <optional>
'sans-serif' The font type colorstring <optional>
'black' The color of the text opacitynumber <optional>
100 The percentage of opacity for the watermark headerobject <optional>
Settings for a header watermark Properties
Name Type Argument Default Description leftstring <optional>
The text content to be rendered at the left side of the header centerstring <optional>
The text content to be rendered at the center of the header rightstring <optional>
The text content to be rendered at the right side of the header fontSizenumber <optional>
20 The font size of the text, measured in pixels (px) fontFamilystring <optional>
'sans-serif' The font type colorstring <optional>
'black' The color of the text opacitynumber <optional>
100 The percentage of opacity for the watermark footerobject <optional>
Settings for a footer watermark Properties
Name Type Argument Default Description leftstring <optional>
The text content to be rendered at the left side of the footer centerstring <optional>
The text content to be rendered at the center of the footer rightstring <optional>
The text content to be rendered at the right side of the footer fontSizenumber <optional>
20 The font size of the text, measured in pixels (px) fontFamilystring <optional>
'sans-serif' The font type colorstring <optional>
'black' The color of the text opacitynumber <optional>
100 The percentage of opacity for the watermark customCore.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. shouldDrawOverAnnotationsboolean <optional>
false Toggles if the watermark should be drawn over annotations Returns:
A promise that resolves when the watermark is set.- Type
- Promise.<void>
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 pageNumbernumber The page number the point is on xnumber The x position to calculate the snap point from ynumber The y position to calculate the snap point from modenumber <optional>
Enum for an optional snapping mode for the snapping Returns:
A promise that resolves to the SnapData object.- Type
- Promise.<Core.DocumentViewer.SnapData>
-
startSemanticDiff(documentViewer [, options])
-
Compare the text of documents on both DocumentViewers and add annotations to mark the differences.
Parameters:
Name Type Argument Description documentViewerCore.DocumentViewer Other documentViewer to diff with optionsobject <optional>
Properties
Name Type Argument Default Description beforeColorCore.Annotations.Color <optional>
{ R: 255, G: 73, B: 73, A: 0.4 } Color for the highlight annotations on the before document afterColorCore.Annotations.Color <optional>
{ R: 21, G: 205, B: 131, A: 0.4 } Color for the highlight annotations on the after document extraMoveHighlightboolean <optional>
false Whether to highlight text in between short-distance moves Returns:
returns an object with the following properties { doc1Annotations, doc2Annotations, diffCount }- Type
- Promise.<object>
-
stopPageRender(pageNumber)
-
Stops the rendering of the specified page.
Parameters:
Name Type Description pageNumbernumber 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 patternstring The text to search for. modenumber The options for search, controlling options such as case sensitivity and search direction. searchOptionsobject <optional>
An object that can contain the following optional parameters Properties
Name Type Argument Description fullSearchboolean <optional>
If true, a search of the entire document will be performed. Otherwise, a single search will be performed. onResultfunction <optional>
(result) The callback function that is called when the search returns a result. onPageEndfunction <optional>
(result) The callback function that is called when reaching the end of the page (if using page_stop mode). onDocumentEndfunction <optional>
() The callback function that is called when reaching the end of the document. onErrorfunction <optional>
(result) The callback function that is called when search failed or regex has syntax error. startPagenumber <optional>
Page to start the search on (1-indexed). endPagenumber <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:
-
- Core.DocumentViewer#SearchMode
-
trigger(type [, data])
-
Calls the handlers of the event name with given data
Parameters:
Name Type Argument Description typestring | 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
myObject.trigger('eventName'); myObject.trigger('eventName', [eventParameter1, eventParameter2]); -
updateLinks(pageNumber)
-
Updates old xod (version <= 1.2) link annotations in the annotation manager
Parameters:
Name Type Description pageNumbernumber 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 Argument Description visiblePagesArray.<number> <optional>
An array of integers representing the pages to render. currentPageNumbernumber <optional>
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 Argument Description visiblePagesArray.<number> <optional>
An array of integers representing the pages to render. -
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 zoomnumber Zoom value. xnumber <optional>
Horizontal position to scroll to. ynumber <optional>
Vertical position to scroll to. -
zoomToMouse(zoom, offsetX, offsetY [, event])
-
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 Argument Description zoomnumber Zoom value offsetXnumber The x offset from the mouse position to the viewer's position (e.g. taking into account toolbars) offsetYnumber The y offset from the mouse position to the viewer's position (e.g. taking into side panels) eventMouseEvent <optional>
A DOM mouse event. If used then the mouse will be zoomed to the location of where this event originated.
Type Definitions
-
CustomWatermarkCallback(ctx, pageIndex, pageWidth, pageHeight)
-
Parameters:
Name Type Description ctxCanvasRenderingContext2D The Canvas Context that determines how the watermark will be rendered. Edit the text styles attributes to change the rendering styling. pageIndexnumber The index of the current page pageWidthnumber The width of the current page pageHeightnumber The height of the current page -
DocumentXFDFRetriever(docId)
-
Parameters:
Name Type Description docIdstring 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>)>
-
onToggleOffBookmarkShortcut(pageIndex)
-
Parameters:
Name Type Description pageIndexnumber A parameter for the 0-index based page number Returns:
- Type
- void
-
onToggleOnBookmarkShortcut(pageIndex)
-
Parameters:
Name Type Description pageIndexnumber A parameter for the 0-index based page number Returns:
- Type
- void
-
pagesUpdatedChanges
-
Type:
- Object
Properties:
Name Type Description addedArray.<number> Array of page numbers that were added removedArray.<number> Array of page numbers that were removed movedObject An object mapping page number changes. E.g. if Page 2 was moved to now be page 3 it would be: { 2: 3, 3: 2 } contentChangedArray.<number> Array of page numbers that had their content change annotationsChangedArray.<number> Array of page numbers that had their annotations change linearizedUpdateboolean Boolean representing whether this page update was from the initial download of the file when the proper page sizes are loaded. This will only happen for linearized PDFs. -
SnapData
-
Type:
- Object
Properties:
Name Type Description xnumber The x position of the nearestPoint ynumber The y position of the nearestPoint modenumber The effective mode that was used to find this snap point. modeNamestring The name of the effective mode that was used to find this snap point.
Events
-
activeSearchResultChanged
-
Triggered when the active search result has changed
Parameters:
Name Type Description resultobject The new active search result, Core.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
-
click
-
Triggered for the click event in the DocumentViewer's viewing area
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
compareAnnotationsLoaded
-
Triggered when Core.DocumentViewer.startSemanticDiff is called
Parameters:
Name Type Description doc1Annotationsobject Highlight annotations marking the difference on the first document doc2Annotationsobject Highlight annotations marking the difference on the second document diffCountobject The number of differences between the two documents -
dblClick
-
Triggered for the dblClick event in the DocumentViewer's viewing area
Parameters:
Name Type Description nativeEvtobject 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 pageNumnumber The 1-indexed page number verticalOffsetnumber The offset from the top of the page horizontalOffsetnumber 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
-
embeddedThumbnailComplete
-
Triggered when an embedded thumbnail of a viewer-optimized pdf is completely loaded.
Parameters:
Name Type Description pageNumnumber The 1-indexed page number -
finishedRendering
-
Triggered when DocumentViewer finishes rendering pages
-
fitModeUpdated
-
Triggered when the fit mode has changed
Parameters:
Name Type Description fitModeobject 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 nativeEvtobject Event object of the native JavaScript event -
keyUp
-
Triggered for the keyUp event in the DocumentViewer's viewing area
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
longTap
-
Triggered on mobile when there is a long tap in the DocumentViewer's viewing area. This is the equivalent of the desktop right click. Long taps are defined as pressing a mouse and holding it down for 500ms before releasing it. If e.preventDefault() is called, the currently selected tool won't get activated. Use this to provide your custom handling of this event, for example adding a menu after a long tap.
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
mouseEnter
-
Triggered for the mouseEnter event in the DocumentViewer's viewing area
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
mouseLeave
-
Triggered for the mouseLeave event in the DocumentViewer's viewing area
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
mouseLeftDown
-
Triggered for the mouseLeftButtonDown event in the DocumentViewer's viewing area Attach like docViewer.addEventListener('mouseLeftDown', callback)
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
mouseLeftUp
-
Triggered for the mouseLeftButtonUp event in the DocumentViewer's viewing area
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
mouseMove
-
Triggered for the mouseMove event in the DocumentViewer's viewing area
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
mouseRightDown
-
Triggered for the mouseRightButtonDown event in the DocumentViewer's viewing area
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
mouseRightUp
-
Triggered for the mouseRightButtonUp event in the DocumentViewer's viewing area
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
notify
-
Triggered when there is a notification relating to searching or annotation permissions.
Parameters:
Name Type Description typestring The type of notification that has occurred -
pageComplete
-
Triggered when a page has been completely rendered.
Parameters:
Name Type Description pageNumnumber The 1-indexed page number canvasHTMLCanvasElement The canvas for the page -
pageNumberUpdated
-
Triggered when the page number is updated
Parameters:
Name Type Description pageNumbernumber The new page number (1-indexed) -
pagesUpdated
-
Triggered when the layout has changed because pages have permanently been added, removed, moved or changed in some other way.
Parameters:
Name Type Description changesCore.DocumentViewer.pagesUpdatedChanges An object with keys added, removed, moved and contentChanged, indicating which pages have changed -
rotationUpdated
-
Triggered when the page rotation has changed
Parameters:
Name Type Argument Description rotationCore.PageRotation The new viewing rotation. pageNumbernumber <optional>
Optionally the specific page number that had its rotation changed -
searchInProgress
-
Triggered when a search starts or ends. When Core.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 inProgressboolean Whether a search is in progress or not isFullSearchboolean Whether this is a full text search or not -
searchResultsChanged
-
Triggered when the search results list has changed
Parameters:
Name Type Description resultsArray.<object> The new search results, Core.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.
Parameters:
Name Type Description nativeEvtobject Event object of the native JavaScript event -
textSelected
-
Triggered when the selected text has changed
Parameters:
Name Type Description quadsArray.<Core.Math.Quad> An array of bounding box quads of the selected text textstring The selected text pageNumbernumber The page number that the text was selected on -
toolModeUpdated
-
Triggered when the tool mode has changed
Parameters:
Name Type Description newToolObjectobject The tool object that has been changed to. oldToolObjectobject The tool object that has been changed from. -
toolUpdated
-
Triggered when the tool styles or tool name have changed
Parameters:
Name Type Description toolModeClassobject The tool object that has been changed. -
zoomUpdated
-
Triggered when the zoom level has been updated
Parameters:
Name Type Description zoomnumber The new zoom level of the viewer