Class 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.
Constructor Attributes | Constructor Name and Description |
---|---|
Creates a new empty DocumentViewer.
|
Field Attributes | Field Name and Description |
---|---|
Default values for document viewer.
|
Method Attributes | Method Name and Description |
---|---|
Clears any selected text on the all pages.
|
|
Reinitializes data and clears the viewer area content.
|
|
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.
|
|
Scrolls the viewer so that the upper-left corner of the Document's first page is in the upper-left corner of the viewer.
|
|
Scrolls the viewer so that the upper-left corner of the Document's last page is in the upper-left corner of the viewer.
|
|
displaySearchResult(result, jump)
Scrolls the viewer so that the position of the search result is in the middle of the viewer.
|
|
dispose()
Disposes the current document's data
|
|
drawSelection(pageNumber)
Draws the text selection for the specified page.
|
|
Returns the AnnotationManager used by this DocumentViewer
|
|
getCompleteRotation(pageNumber)
Returns the complete rotation of the page including the document's rotation.
|
|
Returns the current page number
|
|
Returns the DisplayModeManager used by this DocumentViewer
|
|
Returns the Document that is currently being displayed by the viewer.
|
|
Returns the current fit mode.
|
|
Returns a pixel value, representing the left, right, top and bottom margins.
|
|
Returns the number of pages in a document.
|
|
getPageHeight(pageIndex)
Get the current height of the specified page, taking into account rotation.
|
|
Gets the individual page rotations of the document.
|
|
getPageWidth(pageIndex)
Get the current width of the specified page, taking into account rotation.
|
|
getPageZoom(pageIndex)
Get the zoom value for a particular page.
|
|
Returns the page rendering order.
|
|
getRotation(pageNumber)
Returns the current viewing rotation.
|
|
Returns the text selected by text selection tool or search.
|
|
Returns the current tool.
|
|
getZoom()
Returns the current zoom level
|
|
loadAsync(partRetriever, options)
Initialize the viewer and load a .xod document into the viewer.
|
|
recalculateLayout(pagesToRecalculate)
Request a recalculation of page layout and rerender all pages.
|
|
removeContent(removeData, rotationChanged)
Removes all the page content from the DOM.
|
|
returnCanvas(pageIndex, canvas)
Returns the canvas so that it can be reused.
|
|
rotateClockwise(pageNumber)
Rotates all pages in the currently displayed document clockwise by 90 degrees.
|
|
rotateCounterClockwise(pageNumber)
Rotates all pages in the currently displayed document counter-clockwise by 90 degrees.
|
|
This function must be called after modifying the ScrollView (#DocumentViewer) element's dimensions or properties.
|
|
select(pt1, pt2)
Selects the text content of the document given two page coordinates.
|
|
setCurrentPage(pageNumber)
Sets the current page.
|
|
setFitMode(fitMode)
Sets how the document will scale to fit the size of the scrollviewer's viewport.
|
|
setInternalAnnotationsTransform(handler(annotationData,callback))
Allows you to transform (or replace) the internal annotations of the document.
|
|
setMargin(margin)
Set the pixel value to use for the left, right, top and bottom margins.
|
|
setOptions(options)
Sets specific DocumentViewer options.
|
|
setPageRotations(rotations)
Sets the individual page rotations of multiple pages at once.
|
|
setPagesPerCanvas(numPages, isCover)
Sets the number of pages that will be visible on each canvas.
|
|
setPageZoom(pageIndex, zoom)
Sets the zoom for a particular page.
|
|
setRightToLeftPages(rightToLeftPages)
Sets the page rendering order.
|
|
setRotation(pageRotation, pageNumber)
Sets the current viewing rotation.
|
|
setTextHighlightColor(color)
Sets the color to use when highlighting text from text selection or searching.
|
|
setToolMode(tool)
Sets the tool mode.
|
|
stopPageRender(pageIndex)
Stops the rendering of the specified page.
|
|
textSearchInit(pattern, mode, fullSearch, onSearchCallback(result))
Searches for a particular text string on the currently displayed Document, starting on the current page.
|
|
updateLinks(pageIndex)
Updates old xod (version <= 1.2) link annotations in the annotation manager
|
|
updateView(visiblePages, currentPageIndex)
Removes previously drawn pages that are no longer visible and
draws pages that are visible and have not been drawn.
|
|
updateVisiblePages(visiblePages)
Notifies the document viewer that the visible pages have changed
but does not draw any pages.
|
|
zoomTo(zoom, x, y)
Adjusts the viewer's zoom factor, and positions the point (x,y) at the upper left corner of the viewer.
|
|
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.
|
Event Attributes | Event Name and Description |
---|---|
beforeDocumentLoaded(evt)
Triggered just before the document has been loaded into the viewer
|
|
changePage(evt, pageNum)
Triggered when the page should be changed.
|
|
dblClick(evt, nativeEvt)
Triggered for the dblClick event in the DocumentViewer's viewing area
|
|
displayModeUpdated(evt)
Triggered when the display mode is updated
|
|
displayPageLocation(evt, pageNum, verticalOffset, horizontalOffset)
Triggered when a page location should be displayed
|
|
documentLoaded(evt)
Triggered when the document has been loaded
|
|
fitModeUpdated(evt, fitMode)
Triggered when the fit mode has changed
|
|
keyDown(evt, nativeEvt)
Triggered for the keyDown event in the DocumentViewer's viewing area
|
|
keyUp(evt, nativeEvt)
Triggered for the keyUp event in the DocumentViewer's viewing area
|
|
layoutChanged(evt, changes)
Triggered when the layout has changed because pages have permanently been added, removed, moved or changed in some other way.
|
|
linkReady(evt, linkElement, link)
Triggered when a link is created on the page.
|
|
mouseEnter(evt, nativeEvt)
Triggered for the mouseEnter event in the DocumentViewer's viewing area
|
|
mouseLeave(evt, nativeEvt)
Triggered for the mouseLeave event in the DocumentViewer's viewing area
|
|
mouseLeftDown(evt, nativeEvt)
Triggered for the mouseLeftButtonDown event in the DocumentViewer's viewing area
Attach like docViewer.on('mouseLeftDown', callback)
|
|
mouseLeftUp(evt, nativeEvt)
Triggered for the mouseLeftButtonUp event in the DocumentViewer's viewing area
|
|
mouseMove(evt, nativeEvt)
Triggered for the mouseMove event in the DocumentViewer's viewing area
|
|
mouseRightDown(evt, nativeEvt)
Triggered for the mouseRightButtonDown event in the DocumentViewer's viewing area
|
|
mouseRightUp(evt, nativeEvt)
Triggered for the mouseRightButtonUp event in the DocumentViewer's viewing area
|
|
pageComplete(evt, pageIndex, canvas)
Triggered when a page has been completely rendered.
|
|
pageNumberUpdated(evt, pageNumber)
Triggered when the page number is updated
|
|
rotationUpdated(evt, rotation, pageNumber)
Triggered when the page rotation has changed
|
|
textSelected(evt, quads, text, pageIndex)
Triggered when the selected text has changed
|
|
toolModeUpdated(evt, toolModeClass)
Triggered when the tool mode has changed
|
|
zoomUpdated(evt, zoom)
Triggered when the zoom level has been updated
|
Field Detail
{object}
defaults
Default values for document viewer. Set FitMode, DisplayMode or Zoom.
Method Detail
clearSelection()
Clears any selected text on the all pages.
closeDocument()
Reinitializes data and clears the viewer area content.
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:
- {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.
displaySearchResult(result, jump)
Scrolls the viewer so that the position of the search result is in the middle of the viewer.
- Parameters:
- {Object} result
- The result of a search, DocumentViewer.SearchResults. Returned by onSearchCallback in CoreControls.DocumentViewer#textSearchInit.
- {function} jump
- The callback for navigating to the found result.
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:
- {number} pageNumber
- The page number to draw the selection on
{AnnotationManager}
getAnnotationManager()
Returns the AnnotationManager used by this DocumentViewer
- Returns:
- {AnnotationManager} an instance of AnnotationManager
{CoreControls.PageRotation}
getCompleteRotation(pageNumber)
Returns the complete rotation of the page including the document's rotation.
- Parameters:
- {number} pageNumber Optional
- Optionally pass the page number to get the specific page's rotation
- Returns:
- {CoreControls.PageRotation} The current complete rotation.
{number}
getCurrentPage()
Returns the current page number
- Returns:
- {number} The current 1-indexed page number.
{DisplayModeManager}
getDisplayModeManager()
Returns the DisplayModeManager used by this DocumentViewer
- Returns:
- {DisplayModeManager} an instance of DisplayModeManager
{CoreControls.Document}
getDocument()
Returns the Document that is currently being displayed by the viewer.
- Returns:
- {CoreControls.Document} returns the current document.
{DocumentViewer.FitMode}
getFitMode()
Returns the current fit mode.
- Returns:
- {DocumentViewer.FitMode} The current fit mode.
{number}
getMargin()
Returns a pixel value, representing the left, right, top and bottom margins.
- Returns:
- {number} The margin value.
{number}
getPageCount()
Returns the number of pages in a document.
- Returns:
- {number} The number of the pages in the current document.
{number}
getPageHeight(pageIndex)
Get the current height of the specified page, taking into account rotation.
- Parameters:
- {int} pageIndex
- The page index
- Returns:
- {number} The height of the page
{object}
getPageRotations()
Gets the individual page rotations of the document. Only returns pages that have been rotated individually.
- Returns:
- {object} An object with keys that are page indexes (0-indexed) and values that are rotation values.
{number}
getPageWidth(pageIndex)
Get the current width of the specified page, taking into account rotation.
- Parameters:
- {int} pageIndex
- The page index
- Returns:
- {number} The width of the page
getPageZoom(pageIndex)
Get the zoom value for a particular page.
- Parameters:
- {int} pageIndex
- The page index.
{boolean}
getRightToLeftPages()
Returns the page rendering order.
- Returns:
- {boolean} The current page rendering order.
{CoreControls.PageRotation}
getRotation(pageNumber)
Returns the current viewing rotation.
PageRotation.e_0 = 0 (0 degress)
PageRotation.e_90 = 1 (90 degress)
PageRotation.e_180 = 2 (180 degress)
PageRotation.e_270 = 3 (270 degress)
- Parameters:
- {number} pageNumber Optional
- Optionally pass the page number to get the specific page's rotation
- Returns:
- {CoreControls.PageRotation} The current viewing rotation.
{string}
getSelectedText()
Returns the text selected by text selection tool or search.
- Returns:
- {string} Selected text.
{window.Tools}
getToolMode()
Returns the current tool.
- Returns:
- {window.Tools} The current tool.
{number}
getZoom()
Returns the current zoom level
- Returns:
- {number} The current zoom level.
loadAsync(partRetriever, options)
Initialize the viewer and load a .xod document into the viewer.
- Parameters:
- {HttpPartRetriever|LocalPartRetriever|StreamingPartRetriever} partRetriever
- An instance of PartRetriever.
- options
- an object that can contain the following optional parameters
- {string} options.docId Optional
- An optional unique identifier for the document, used for offline mode
- {function} options.onError Optional
- A callback of the form function(err) which will be called when a loading error occurs.
- {promise} options.workerTransportPromise 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
- {function} options.getPassword 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.
- {string} options.extension 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
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:
- pagesToRecalculate
removeContent(removeData, rotationChanged)
Removes all the page content from the DOM.
Also clear the cache if the zoom or rotation has changed.
- Parameters:
- {bool} removeData
- Whether or not to remove all event handlers and data on the elements
- rotationChanged
returnCanvas(pageIndex, canvas)
Returns the canvas so that it can be reused. Should be called when the canvas is no longer used by the viewer.
Only valid in viewport canvas mode.
- Parameters:
- {number} pageIndex
- The page index of the canvas
- {object} canvas
- The canvas element to return
rotateClockwise(pageNumber)
Rotates all pages in the currently displayed document clockwise by 90 degrees.
- Parameters:
- {number} pageNumber 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:
- {number} pageNumber Optional
- Optionally pass the page number to rotate only a specific page
scrollViewUpdated()
This function must be called after modifying the ScrollView (#DocumentViewer) element's dimensions or properties.
select(pt1, pt2)
Selects the text content of the document given two page coordinates.
- Parameters:
- pt1
- Starting page coordinate. Requires properties x, y and pageIndex.
- pt2
- Ending page coordinate. Requires properties x, y and pageIndex.
setCurrentPage(pageNumber)
Sets the current page. Updates the current page and jumps to it.
- Parameters:
- {int} pageNumber
- The page number to jump to.
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:
- {DocumentViewer.FitMode} fitMode
setInternalAnnotationsTransform(handler(annotationData,callback))
Allows you to transform (or replace) the internal annotations of the document.
- Parameters:
- {function} handler(annotationData,callback)
- A handler function that takes annotation data and a callback that is called when the transformed data is ready
setMargin(margin)
Set the pixel value to use for the left, right, top and bottom margins.
- Parameters:
- margin
setOptions(options)
Sets specific DocumentViewer options.
- Parameters:
- {object} options
- 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:
- {object} rotations
- An object with keys that are page indexes (0-indexed) and values that are rotation values. Rotations should be specified as {CoreControls.PageRotation}s
setPagesPerCanvas(numPages, isCover)
Sets the number of pages that will be visible on each canvas.
Only valid in viewport canvas mode.
- Parameters:
- numPages
- isCover
setPageZoom(pageIndex, zoom)
Sets the zoom for a particular page. Should be followed by a call to updateView to actually render the page.
- Parameters:
- {int} pageIndex
- The page index.
- {float} zoom
- Zoom value for page.
setRightToLeftPages(rightToLeftPages)
Sets the page rendering order.
- Parameters:
- {boolean} rightToLeftPages
- Whether the new page rendering order should be right to left or not.
setRotation(pageRotation, pageNumber)
Sets the current viewing rotation.
- Parameters:
- {CoreControls.PageRotation} pageRotation
- desired viewing rotation.
- {number} pageNumber Optional
- Optionally pass the page number to set the specific page's rotation
setTextHighlightColor(color)
Sets the color to use when highlighting text from text selection or searching.
- Parameters:
- {string} color
- 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:
- {Tools.Tool} tool
- An instance of the toolmode
stopPageRender(pageIndex)
Stops the rendering of the specified page.
- Parameters:
- {number} pageIndex
- The index of the page who's rendering should be stopped.
textSearchInit(pattern, mode, fullSearch, onSearchCallback(result))
Searches for a particular text string on the currently displayed Document, starting on the current page.
- Parameters:
- {string} pattern
- The text to search for.
- {DocumentViewer.SearchMode} mode
- The options for search, controlling options such as case sensitivity and search direction.
- {boolean} fullSearch
- If true, a search of the entire document will be performed. Otherwise, a single search will be perfomed.
- {function} onSearchCallback(result)
- The callback function to call when the search completes. 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.
updateLinks(pageIndex)
Updates old xod (version <= 1.2) link annotations in the annotation manager
- Parameters:
- {number} pageIndex
- The zero-indexed page number to update
updateView(visiblePages, currentPageIndex)
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:
- {Object} visiblePages
- An array of integers representing the pages to render.
- {number} currentPageIndex
- The index 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:
- visiblePages
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:
- {float} zoom
- Zoom value.
- {int} x Optional
- Horizontal position to scroll to.
- {int} y 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:
- {float} zoom
- Zoom value
- {int} offsetX
- The x offset from the mouse position to the viewer's position (e.g. taking into account toolbars)
- {int} offsetY
- The y offset from the mouse position to the viewer's position (e.g. taking into side panels)
Event Detail
beforeDocumentLoaded(evt)
Triggered just before the document has been loaded into the viewer
- Parameters:
- {object} evt
- jQuery's event object
changePage(evt, pageNum)
Triggered when the page should be changed.
Only fired when using a non-scrollable custom display mode.
- Parameters:
- {object} evt
- jQuery's event object
- {int} pageNum
- The 1-indexed page number
dblClick(evt, nativeEvt)
Triggered for the dblClick event in the DocumentViewer's viewing area
- Parameters:
- {object} evt
- jQuery's event object
- {object} nativeEvt
- Event object of the native JavaScript event
displayModeUpdated(evt)
Triggered when the display mode is updated
- Parameters:
- {object} evt
- jQuery's event object
displayPageLocation(evt, pageNum, verticalOffset, horizontalOffset)
Triggered when a page location should be displayed
- Parameters:
- {object} evt
- jQuery's event object
- {int} pageNum
- The 1-indexed page number
- {float} verticalOffset
- The offset from the top of the page
- {float} horizontalOffset
- The offset from the left of the page
documentLoaded(evt)
Triggered when the document has been loaded
- Parameters:
- {object} evt
- jQuery's event object
fitModeUpdated(evt, fitMode)
Triggered when the fit mode has changed
- Parameters:
- {object} evt
- jQuery's event object
- {object} fitMode
- The fit mode that has been changed to e.g. docViewer.FitMode.FitWidth
keyDown(evt, nativeEvt)
Triggered for the keyDown event in the DocumentViewer's viewing area
- Parameters:
- {object} evt
- jQuery's event object
- {object} nativeEvt
- Event object of the native JavaScript event
keyUp(evt, nativeEvt)
Triggered for the keyUp event in the DocumentViewer's viewing area
- Parameters:
- {object} evt
- jQuery's event object
- {object} nativeEvt
- Event object of the native JavaScript event
layoutChanged(evt, changes)
Triggered when the layout has changed because pages have permanently been added, removed, moved or changed in some other way.
- Parameters:
- {object} evt
- jQuery's event object
- {object} changes
- An object with keys added, removed, moved and contentChanged, indicating which pages have changed
linkReady(evt, linkElement, link)
Triggered when a link is created on the page.
- Parameters:
- {object} evt
- jQuery's event object
- {object} linkElement
- The HTML span element that represents the link
- {object} link
- Link object that contains more information about the link
mouseEnter(evt, nativeEvt)
Triggered for the mouseEnter event in the DocumentViewer's viewing area
- Parameters:
- {object} evt
- jQuery's event object
- {object} nativeEvt
- Event object of the native JavaScript event
mouseLeave(evt, nativeEvt)
Triggered for the mouseLeave event in the DocumentViewer's viewing area
- Parameters:
- {object} evt
- jQuery's event object
- {object} nativeEvt
- Event object of the native JavaScript event
mouseLeftDown(evt, nativeEvt)
Triggered for the mouseLeftButtonDown event in the DocumentViewer's viewing area
Attach like docViewer.on('mouseLeftDown', callback)
- Parameters:
- {object} evt
- jQuery's event object
- {object} nativeEvt
- Event object of the native JavaScript event
mouseLeftUp(evt, nativeEvt)
Triggered for the mouseLeftButtonUp event in the DocumentViewer's viewing area
- Parameters:
- {object} evt
- jQuery's event object
- {object} nativeEvt
- Event object of the native JavaScript event
mouseMove(evt, nativeEvt)
Triggered for the mouseMove event in the DocumentViewer's viewing area
- Parameters:
- {object} evt
- jQuery's event object
- {object} nativeEvt
- Event object of the native JavaScript event
mouseRightDown(evt, nativeEvt)
Triggered for the mouseRightButtonDown event in the DocumentViewer's viewing area
- Parameters:
- {object} evt
- jQuery's event object
- {object} nativeEvt
- Event object of the native JavaScript event
mouseRightUp(evt, nativeEvt)
Triggered for the mouseRightButtonUp event in the DocumentViewer's viewing area
- Parameters:
- {object} evt
- jQuery's event object
- {object} nativeEvt
- Event object of the native JavaScript event
pageComplete(evt, pageIndex, canvas)
Triggered when a page has been completely rendered.
- Parameters:
- {object} evt
- jQuery's event object
- {object} pageIndex
- The 0-indexed page index
- {object} canvas Optional
- The canvas for the page
pageNumberUpdated(evt, pageNumber)
Triggered when the page number is updated
- Parameters:
- {object} evt
- jQuery's event object
- {int} pageNumber
- The new page number (1-indexed)
rotationUpdated(evt, rotation, pageNumber)
Triggered when the page rotation has changed
- Parameters:
- {object} evt
- jQuery's event object
- {CoreControls.PageRotation} rotation
- The new viewing rotation.
- {number} pageNumber Optional
- Optionally the specific page number that had its rotation changed
textSelected(evt, quads, text, pageIndex)
Triggered when the selected text has changed
- Parameters:
- {object} evt
- jQuery's event object
- {array} quads
- An array of bounding box quads of the selected text
- {string} text
- The selected text
- {int} pageIndex
- The zero-indexed page number that the text was selected on
toolModeUpdated(evt, toolModeClass)
Triggered when the tool mode has changed
- Parameters:
- {object} evt
- jQuery's event object
- {object} toolModeClass
- The tool mode class that has been changed to.
zoomUpdated(evt, zoom)
Triggered when the zoom level has been updated
- Parameters:
- {object} evt
- jQuery's event object
- {int} zoom
- The new zoom level of the viewer