new WebViewer(options, element)
Creates a WebViewer instance and embeds it on the HTML page.
Parameters:
Name | Type | Description |
---|---|---|
options |
PDFTron.WebViewer.Options | Options passed to the specific WebViewer. |
element |
DOMElement | The html element that will contain the web viewer (e.g. the element that will be parent of the WebViewer). This can be obtained through document.getElementById(), or through JQuery selector. |
Returns:
The instance of the WebViewer class.
- Type
- PDFTron.WebViewer
Example
var viewerElement = document.getElementById('viewer'); myWebViewer = new PDFTron.WebViewer({ type: 'html5,html5Mobile', initialDoc : '/host/GettingStarted.xod', enableAnnotations: true, streaming : false }, viewerElement);
Classes
Members
-
<static> FitMode
-
Contains all posible modes for fitting/zooming pages to the viewer. The behavior may vary depending on the LayoutMode.
Properties:
Name Type Description FitHeight
string A fit mode where the zoom level is fixed to the height of the page.
FitPage
string A fit mode where the zoom level is fixed to the width or height of the page, whichever is smaller.
FitWidth
string A fit mode where the zoom level is fixed to the width of the page.
Zoom
string A fit mode where the zoom level is not fixed.
-
<static> LayoutMode
-
Contains string enums for all layouts for WebViewer. They are used to dictate how pages are placed within the viewer. Used by setLayoutMode and getLayoutMode.
Properties:
Name Type Description Continuous
string All pages are visible in one column.
FacingCoverContinuous
string All pages visible, with an even numbered page rendered first. (i.e. The first page of the document is rendered by itself on the right side of the viewer to simulate a book cover.)
Facing
string Up to two pages will be visible.
FacingContinuous
string All pages visible in two columns.
FacingCover
string All pages visible in two columns, with an even numbered page rendered first. (i.e. The first page of the document is rendered by itself on the right side of the viewer to simulate a book cover.)
Single
string Only the current page will be visible.
-
<static> ToolMode
-
Contains string enums for all default tools for WebViewer. They range from panning, text selection to annotation creation. Used by setToolMode and getToolMode.
Properties:
Name Type Description AnnotationCreateArrow
string Draw an arrow.
AnnotationCreateCallout
string Draw a callout text box.
AnnotationCreateEllipse
string Draw an ellipse.
AnnotationCreateFreeHand
string Draw a freehand line.
AnnotationCreateFreeText
string Draw a text box.
AnnotationCreateLine
string Draw a straight line.
AnnotationCreatePolygon
string Draw a polygon.
AnnotationCreatePolygonCloud
string Draw a cloud.
AnnotationCreatePolyline
string Draw a series of connected straight lines.
AnnotationCreateRectangle
string Draw a rectangle.
AnnotationCreateSignature
string Add a signature.
AnnotationCreateStamp
string Add an image.
AnnotationCreateSticky
string Add a sticky note.
AnnotationCreateTextHighlight
string Highlight texts.
AnnotationCreateTextSquiggly
string Undeline texts squiggly.
AnnotationCreateTextStrikeout
string Strike out texts.
AnnotationCreateTextUnderline
string Undeline texts.
AnnotationEdit
string Select/edit annotations (default).
-
Options
-
Options object for WebViewer on creation. Used when constructing a new PDFTron.WebViewer instance.
Properties:
Name Type Argument Default Description initialDoc
string The URL path to a xod document to load on startup.
annotationAdmin
boolean <optional>
A boolean indicating this user has permission to modify all annotations, even if the annotationUser and author does not match.
annotationUser
string <optional>
A user identifier for annotations. All annotations created will have this as the author. It is used for permission checking: user only permitted to modify annotations where annotationUser and author matches.
autoCreate
boolean <optional>
true A boolean to control whether the viewer should be created after instantiating a new PDFTron.WebViewer. When set to false, invoke the create() method explicity.
azureWorkaround
boolean <optional>
false 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.
backgroundColor
string <optional>
A string to set the background color of the inner page to (desktop only).
cloudApiId
string <optional>
The share ID or session ID created from PWS Cloud. Note: the browser must have CORS support (ignored when initialDoc is also set).
config
string <optional>
A URL path to a JavaScript configuration file that holds UI customizations.
custom
string <optional>
A string of custom data that can be retrieved by the ReaderControl.
documentId
string <optional>
An identifier for the document to be used with annotations. (required for full annotation support).
documentType
string <optional>
The type of document the viewer will be used with. Valid values are "xod" and "pdf" (default is "xod").
enableAnnotations
boolean <optional>
true A boolean to enable annotations.
enableOfflineMode
boolean <optional>
false A boolean to enable offline mode. By default this will add buttons to the UI to allow for saving the document to an offline database. (XOD only)
enableReadOnlyMode
boolean <optional>
false A boolean to enable annotations read-only mode.
encryption
object <optional>
An object containing encryption properties. Expects the object to have type: "aes" and p: "your_document_password" (XOD only).
errorPage
string <optional>
A path to an HTML page to display errors.
externalPath
string <optional>
The path to a xod document folder generated using the external parts option.
hideAnnotationPanel
boolean <optional>
false Whether to hide the annotation panel or not.
html5MobileOptions
Options <optional>
An Options object that overrides the existing options when the Mobile viewer is loaded.
html5MobilePath
string <optional>
html5/MobileReaderControl.html An alternative path to the Mobile WebViewer, relative to the "path" option.
html5Options
Options <optional>
An Options object that overrides the existing options when the viewer is loaded.
html5Path
string <optional>
html5/ReaderControl.html An alternative path to the WebViewer, relative to the "path" option.
l
string <optional>
The license key for viewing PDF files (PDF only).
mobileRedirect
boolean <optional>
true A boolean indicating whether the mobile viewer should redirect to a new window or not. By default this is true because mobile browsers have had issues with iframes in the past. (mobile only).
path
string <optional>
An alternative path to the WebViewer root folder.
pdfBackend
string <optional>
A string to control PDF engine ["auto", "ems", "pnacl"] (PDF only, default "auto" chooses the best option availible)
pdfnet
boolean <optional>
false A boolean to enable the use of PDFNet.js library functions (PDF only).
preloadPDFWorker
boolean <optional>
true A boolean to enable the preloading of the PDF worker files (PDF only).
serverUrl
string <optional>
A URL to the server-side script that handles annotations. (required for full annotation support).
showLocalFilePicker
boolean <optional>
false A boolean to show/hide the local file picker (PDF only).
showPageHistoryButtons
boolean <optional>
true A boolean to show/hide the page history buttons.
showToolbarControl
boolean <optional>
A boolean to show/hide the default toolbar control.
startOffline
boolean <optional>
false 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.
streaming
boolean <optional>
false A boolean indicating whether to use http or streaming PartRetriever, it is recommended to keep streaming false for better performance.
type
string <optional>
html5,html5Mobile The type of WebViewer to load. Values must be comma-separated in order of preferred WebViewer (possibe values: html5, html5Mobile).
useDownloader
boolean <optional>
true Enable or disable using Downloader on urls (PDF only).
workerTransportPromise
boolean <optional>
A promise that will resolve to a PDF worker, used if you already create a worker on the outer page and want to share it with the viewer (PDF only).
xdomainProxyUrl
string <optional>
A URL to the proxy HTML file on the remote server when using the xdomain CORS workaround. Can also be an object to specify multiple URLs.
subzero
boolean <optional>
Enable or disable using PNaCl subzero compiler. With subzero enabled the first load and execution is significantly faster at the expense of slightly slower execution (about 10%) for subsequent usage. Note that subzero is only consistently available on Chrome 51 or above so this flag will be ignored on earlier Chrome versions. (PDF only, default true)
Methods
-
downloadXodDocument()
-
Opens the XOD document through the browser to be downloaded.
- Since:
-
- Version 1.7
-
endPrintJob()
-
Cleans up the resources that were used for printing. (Desktop only)
-
fitHeight()
-
Controls if the document's Zoom property will be adjusted so that the height of the current page or panel will exactly fit into the available space. Not supported for mobile viewer.
- Deprecated:
-
- Since version 1.7. Use setFitMode instead.
-
fitPage()
-
Controls if the document's Zoom property will be adjusted so that the width and height of the current page or panel will fit into the available space. Not supported for mobile viewer.
- Deprecated:
-
- Since version 1.7. Use setFitMode instead.
-
fitWidth()
-
Controls if the document's Zoom property will be adjusted so that the width of the current page or panel will exactly fit into the available space. Not supported for mobile viewer.
- Deprecated:
-
- Since version 1.7. Use setFitMode instead.
-
getCurrentPageNumber()
-
Gets the current page number of the document loaded in the WebViewer.
Returns:
The current page number of the document.
- Type
- number
-
getFitMode()
-
Gets the current fit mode of the viewer.
- Since:
-
- Version 1.7
Returns:
The current fit mode of the viewer.
-
getInstance()
-
Gets the instance of the ReaderControl object loaded by WebViewer.
Returns:
A ReaderControl instance.
- Type
- ReaderControl
-
getLayoutMode()
-
Gets the layout mode of the document in the WebViewer. Not supported for mobile viewer.
Returns:
The layout mode of the document.
-
getPageCount()
-
Gets the total number of pages of the loaded document.
Returns:
The total number of pages of the loaded document.
- Type
- number
-
getShowSideWindow()
-
Gets the value whether the side window is visible or not. Not supported for mobile viewer.
- Deprecated:
-
- Since version 1.7. Replaced by getSideWindowVisibility.
Returns:
true
if the side window is shown.- Type
- boolean
-
getSideWindowVisibility()
-
Gets the visibility of the default side window. Not supported for mobile viewer.
Returns:
true
if the side window is visible.- Type
- boolean
-
getToolbarVisibility()
-
Gets the visibilty of the default toolbar control.
Returns:
true
if the toolbar is visible.- Type
- boolean
-
getToolMode()
-
Gets the current tool mode of the WebViewer. Not supported for mobile viewer.
Returns:
The current tool mode of the WebViewer.
-
getViewerType()
-
Gets the currently loaded viewer type. This is only valid after the documentLoaded event.
Returns:
The viewer type: "html5" or "html5Mobile".
- Type
- string
-
getZoomLevel()
-
Gets the zoom level of the document.
Returns:
The zoom level of the document.
- Type
- number
-
goToFirstPage()
-
Goes to the first page of the document. Makes the document viewer display the first page of the document.
-
goToLastPage()
-
Goes to the last page of the document. Makes the document viewer display the last page of the document.
-
goToNextPage()
-
Goes to the next page of the document. Makes the document viewer display the next page of the document.
-
goToPrevPage()
-
Goes to the previous page of the document. Makes the document viewer display the previous page of the document.
-
isMobileDevice()
-
Detects if the current browser is on a mobile device.
Returns:
true
if this page is loaded on a mobile device.- Type
- boolean
-
isSameOrigin(url)
-
Detects if the give url string is in the same origin as the current page
Parameters:
Name Type Description url
type The URL to test against
Returns:
true
if the provided URL is in the same origin as the current page- Type
- boolean
-
loadDocument(url, loadOptions)
-
Loads a document to the WebViewer.
Parameters:
Name Type Description url
string The URL of the document to be loaded.
loadOptions
object Options for loading a new document.
Properties
Name Type Description documentId
A unique identifer for the document. When an annotation server is specified, this ID will be sent to the server.
filename
The filename of the document.
customHeaders
An object custom HTTP headers to use when retrieving the document from the specified url. For example: {'Authorization' : 'Basic dXNlcm5hbWU6cGFzc3dvcmQ='}
-
rotateClockwise()
-
Rotates the document in the WebViewer clockwise. Not supported for mobile viewer.
-
rotateCounterClockwise()
-
Rotates the document in the WebViewer counter-clockwise. Not supported for mobile viewer.
-
searchText(pattern, searchMode)
-
Searches the loaded document finding for the matching pattern. Search mode includes:
- None
- CaseSensitive
- WholeWord
- SearchUp
- PageStop
- ProvideQuads
- AmbientString
Parameters:
Name Type Description pattern
string The pattern to look for.
searchMode
string Must one or a combination of the above search modes. To combine search modes, simply pass them as comma separated values in one string. i.e. "CaseSensitive,WholeWord"
-
setAdminUser(isAdminUser)
-
Sets the administrative permissions for the current annotation user.
Parameters:
Name Type Description isAdminUser
boolean true
if admin. -
setAnnotationUser(username)
-
Sets the annotation author.
Parameters:
Name Type Description username
string Author of the annotation.
-
setCurrentPageNumber(pageNumber)
-
Sets the current page number of the document loaded in the WebViewer.
Parameters:
Name Type Description pageNumber
number The page number of the document to set.
-
setFitMode(fitMode)
-
Sets the fit mode of the viewer. This is equivalent to calling the methods: fitWidth, fitHeight, fitPage, zoom.
Parameters:
Name Type Description fitMode
PDFTron.WebViewer.FitMode The fit mode to set.
- Since:
-
- Version 1.7
-
setLayoutMode(layoutMode)
-
Sets the layout mode of the document in the WebViewer. Not supported for mobile viewer.
Parameters:
Name Type Description layoutMode
PDFTron.WebViewer.LayoutMode The layout mode to set.
-
setReadOnly(isReadOnly)
-
Sets the viewer's annotation read-only state. When read-only, users will be allowed to view annotations and its popup text contents, but will not be able to edit or create new annotations.
Parameters:
Name Type Description isReadOnly
boolean true
if setting it read-only. -
setShowSideWindow(`true`)
-
Sets the value whether the side window is visible or not. Not supported for mobile viewer.
Parameters:
Name Type Description `true`
boolean to show the side window.
- Deprecated:
-
- Since version 1.7. Replaced by setShowSideWindow.
-
setSideWindowVisibility(value)
-
Gets the visibility of the default side window. Not supported for mobile viewer.
Parameters:
Name Type Description value
boolean true
to show the side window. -
setToolbarVisibility(isVisible)
-
Sets the visibilty of the default toolbar control.
Parameters:
Name Type Description isVisible
boolean true
if the toolbar is visible. -
setToolMode(toolMode)
-
Sets the tool mode of the WebViewer. Not supported for mobile viewer.
Parameters:
Name Type Description toolMode
PDFTron.WebViewer.ToolMode Must be one of the ToolMode.
-
setZoomLevel(zoomLevel)
-
Sets the zoom level of the document.
Parameters:
Name Type Description zoomLevel
number The new zoom level to set.
-
startPrintJob(pages)
-
Starts a printing job for the passed in pages. (Desktop only)
Parameters:
Name Type Description pages
string The pages that should be printed. Multiple pages can be separated by commas and ranges can be specified by a dash (e.g. 1,3-5).
-
zoom()
-
Controls if the document's Zoom property will be freely adjusted and not constrained with the width and height of the current page or panel. Not supported for mobile viewer.
- Deprecated:
-
- Since version 1.7. Use setFitMode instead.
Events
-
displayModeChanged
-
A jQuery event bound on the element, triggered when the display mode has changed.
- Deprecated:
-
- Since version 1.7. Use layoutModeChanged instead.
Example
$('#viewer').bind('displayModeChanged', function(event, data) { //event triggered });
-
documentLoaded
-
A jQuery event bound on the element, triggered when a document has been loaded in the viewer.
Example
$('#viewer').bind('documentLoaded', function(event, data) { //event triggered });
-
layoutModeChanged
-
A jQuery event bound on the element, triggered when the layout mode has changed.
- Since:
-
- Version 1.7
Example
$('#viewer').bind('layoutModeChanged', function(event, data) { //event triggered });
-
pageChanged
-
A jQuery event bound on the element, triggered when the page number has changed.
Example
$('#viewer').bind('pageChanged', function(event, data) { //event triggered });
-
ready
-
A jQuery event bound on the element, triggered when the viewer is ready, before a document is loaded.
Example
$('#viewer').bind('ready', function(event, data) { //event triggered });
-
toolModeChanged
-
A jQuery event bound on the element, triggered when the tool mode has changed.
Example
$('#viewer').bind('toolModeChanged', function(event, data) { //event triggered });
-
zoomChanged
-
A jQuery event bound on the element, triggered when the zoom level has changed.
Example
$('#viewer').bind('zoomChanged', function(event, data) { //event triggered });