Methods
-
getInstance( [element])
-
Gets an already existing instance of WebViewer. If only one instance of WebViewer exists on the page, then 'element' is not required, and the function will return the instance of WebViewer. If more than one instance of WebViewer exists, you must pass in the DOM element containing the instance of WebViewer you want to retrieve. This function can be imported directly as a module as well.
Parameters:
Name Type Argument Description elementHTMLElement <optional>
The DOM element containing the instance of WebViewer you want to retrieve Returns:
Returns an instance of WebViewer. Returns null if no instances are available.- Type
- WebViewerInstance
Example
import { getInstance } from '@pdftron/webviewer' // After WebViewer has already been constructed const instance = getInstance(); -
WebComponent(options, viewerElement)
-
A function that creates an instance of WebViewer, and embeds it on the HTML page This constructor uses a Web Component to embed WebViewer instead of an Iframe.
Parameters:
Name Type Description optionsWebViewerOptions viewerElementHTMLElement Returns:
A promise resolved with WebViewer instance.- Type
- Promise.<WebViewerInstance>
Example
WebViewer.WebComponent({ licenseKey: 'Insert commercial license key here after purchase' }, document.getElementById('viewer')) .then(function(instance) { const documentViewer = instance.Core.documentViewer; const annotationManager = instance.Core.annotationManager; // call methods from instance, documentViewer and annotationManager as needed // you can also access major namespaces from the instances as follows: // const Tools = instance.Core.Tools; // const Annotations = instance.Core.Annotations; }); -
WebViewer(options, viewerElement)
-
A function that creates an instance of WebViewer, and embeds it on the HTML page
Parameters:
Name Type Description optionsWebViewerOptions viewerElementHTMLElement Properties:
Name Type Description WorkerTypesWorkerTypes The types of workers that can be preloaded in WebViewer BackendTypesBackendTypes The types of backend workers . WebComponentWebComponent The WebViewer WebComponent constructor, see WebComponent. IframeWebViewer The default WebViewer constructor, which uses an IFrame. Returns:
A promise resolved with WebViewer instance.- Type
- Promise.<WebViewerInstance>
Example
WebViewer({ licenseKey: 'Insert commercial license key here after purchase' }, document.getElementById('viewer')) .then(function(instance) { const documentViewer = instance.Core.documentViewer; const annotationManager = instance.Core.annotationManager; // call methods from instance, documentViewer and annotationManager as needed // you can also access major namespaces from the instances as follows: // const Tools = instance.Core.Tools; // const Annotations = instance.Core.Annotations; });
Type Definitions
-
AnnotationStyleTabConfiguration
-
Type:
- object
Properties:
Name Type Description styleTabsArray.<string> Indicates the available style tabs in the annotation style popup window. See UI.AnnotationStylePopupTabs. currentStyleTabstring The current tab in the annotation style popup window. -
BackendTypes
-
The types of backend workers. Pass "asm" to force the use of the ASM.js worker, "ems" to force the use of the WebAssembly worker (or ASM.js on non-wasm browsers) or "wasm-threads" to use threaded WebAssembly.
Properties:
Name Type Description ASMstring 'asm' Use of ASM.js worker. WASMstring 'ems' Use of the WebAssembly worker (or ASM.js on non-wasm browsers). THREADED_WASMstring 'wasm-threads' Use of threaded WebAssembly worker. -
ContainerProperties
-
Type:
- Object
Properties:
Name Type Argument Description labelstring <optional>
The label of the container. dataElementstring <optional>
The data element of the container. placement'top' | 'bottom' | 'left' | 'right' <optional>
A string that determines the placement of the header. justifyContent'start' | 'end' | 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly' <optional>
A string that determines the flex justify content value of the container. grownumber <optional>
The flex grow value of the container. gapnumber <optional>
The gap between the items in the container. position'start' | 'center' | 'end' <optional>
A string that determines the position of the container. itemsArray.<Object> <optional>
The items or other containers within the container. styleObject <optional>
An object that can set the CSS style of the container. -
FlyoutItem
-
Represents an item in a flyout with optional submenu.
Type:
- Object
Properties:
Name Type Argument Description dataElementstring <optional>
A unique string that identifies the flyout item. labelstring <optional>
The label of the flyout item. onClickfunction <optional>
A function that is called when the item is clicked. iconstring <optional>
Path to an image or base64 data. Can also be the filename of a .svg from the WebViewer icons folder found here: assets/icons/ (i.e. `icon-save` to use `icon-save.svg`). childrenArray.<FlyoutItem> <optional>
An array of objects that represents the items in a sub-menu, has the same properties as the parent items property and can be infinitely nested. -
ItemProperties
-
Item options
Type:
- Object
Properties:
Name Type Argument Description dataElementstring <optional>
The data element of the item. titlestring <optional>
The tooltip of the item. disabledboolean <optional>
Whether the item is disabled or not. typestring <optional>
The type of the item. -
ItemType
-
Description of allowable item types.
Type:
- 'modularHeader' | 'customButton' | 'statefulButton' | 'groupedItems' | 'ribbonItem' | 'divider' | 'toggleButton' | 'ribbonGroup' | 'toolButton' | 'zoom' | 'flyout' | 'pageControls' | 'presetButton' | 'viewControls' | 'menu' | 'tabPanel'
-
PanelProperties
-
Type:
- Object
Properties:
Name Type Description dataElementstring The data-element for panel. locationstring Location of the panel in UI, left or right. renderstring | UI.renderCustomPanel Either the name of a predefined panel to render or a function that returns a panel element. -
StyleTab
-
The style tab in the annotation style popup window. See UI.AnnotationStylePopupTabs for valid style tabs.
Type:
- string
-
TabPanelItemProperties
-
Type:
- Object
Properties:
Name Type Argument Description dataElementstring <optional>
Unique dataElement name for the panel. iconstring <optional>
Path to an image or base64 data. Can also be the filename of a .svg from the WebViewer icons folder found here: assets/icons/ (i.e. `icon-save` to use `icon-save.svg`). labelstring <optional>
The label to be displayed for the panel in the Tab Panel. renderfunction | string The function that renders the panel or the name of the preset panel. -
TabPanelProperties
-
Type:
- Object
Properties:
Name Type Argument Description dataElementstring Unique dataElement name for the tab panel. panelsListArray.<TabPanelItemProperties> The list of panels to be displayed in the tab panel. locationstring <optional>
The location of the panel. It can be either 'left' or 'right' -
WebViewerOptions
-
Type:
- Object
Properties:
Name Type Argument Default Description pathstring Path to the WebViewer lib folder annotationUserstring <optional>
Guest Name of the user for annotations configstring <optional>
URL path to a custom JavaScript for customizations customstring <optional>
A serialized data object that will be passed into the iframe. The data can be accessed in the config file after deserializing. https://docs.apryse.com/documentation/web/guides/config-files/#passing-custom-data cssstring <optional>
URL path to a custom CSS file for customizations disabledElementsArray.<string> <optional>
List of data-elements to be disabled in UI autoFocusNoteOnAnnotationSelectionboolean <optional>
true Enables auto focus of input in notes panel on selection of annotation accessibleModeboolean <optional>
false Enable accessibility features. E.g tab page selection and page text in the DOM enableAnnotationsboolean <optional>
true Enable annotations feature enableAzureWorkaroundboolean <optional>
false Enable workaround of the issue in Azure related to range requests enableOptimizedWorkersboolean <optional>
true If true, WebViewer will use optimized workers if possible. Otherwise, it will use regular workers enableFilePickerboolean <optional>
false Enable file picker feature enableMeasurementboolean <optional>
false Enable measurement tools enableRedactionboolean <optional>
false Enable redaction tool disableVirtualDisplayModeboolean <optional>
false Disable virtual display mode for pages. The virtual display mode allows documents with many pages to be loaded efficiently in continuous scrolling mode. If disabled then single page mode will be used for documents with many pages. hideDetachedRepliesboolean <optional>
true Whether to hide detached replies. These are replies that reference a parent annotation which no longer exists. extensionstring | Array.<string> <optional>
Extension of the document to be loaded. **Multi-tab** must be an array of documents ex: Webviewer({ initialDoc: ['pdf_doc', 'word_doc'], extension: ['pdf', 'docx'] }) OR Webviewer({ initialDoc: ['pdf_doc1', 'pdf_doc2'], extension: ['pdf'] }) filenamestring <optional>
The name of the file that will be used when downloading the document. The extension in the filename will be used as the document type to be loaded (e.g. myfile.docx will treat the file as docx) if no extension option is passed. forceClientSideInitboolean <optional>
false 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. loadAsPDFboolean <optional>
false If set to true then when loading an office document, it'll be converted to a PDF file. This allow page manipulation and other features to be used fullAPIboolean <optional>
false Enable PDFNet.js library functions initialDocstring | Array.<string> <optional>
URL path to a document to load on startup. If an array of 2 or more documents is passed, webviewer will enable multi-tab mode. isAdminUserboolean <optional>
false Set user permission to admin isReadOnlyboolean <optional>
false Set user permission to read-only licenseKeystring <optional>
License key for viewing documents. If not set then WebViewer will be in demo mode. mobileRedirectboolean <optional>
false Whether the viewer should redirect to a new window or not when loaded on a mobile device preloadWorkerstring <optional>
Type of workers to be preloaded. See WorkerTypes to see all available options. You can also include multiple types comma separated e.g. `${Webviewer.WorkerTypes.PDF},${Webviewer.WorkerTypes.OFFICE}` backendTypestring <optional>
A string representing the "backend type" for rendering PDF and Office documents. Pass "asm" to force the use of the ASM.js worker, "ems" to force the use of the WebAssembly worker (or ASM.js on non-wasm browsers) or "wasm-threads" to use threaded WebAssembly. useDownloaderboolean <optional>
A boolean indicating whether Downloader should be used on urls (PDF only). https://docs.apryse.com/documentation/web/guides/usedownloader-option/. workerTransportPromiseobject <optional>
Properties
Name Type Argument Description pdffunction <optional>
Promise that resolves to a PDF worker officefunction <optional>
Promise that resolves to an office worker webviewerServerURLstring <optional>
The URL path to the hosted WebViewer Server singleServerModeboolean <optional>
false Set server to ignore health failures. For usage with setups using a single server disableLogsboolean <optional>
false Disables console logs coming from WebViewer, including the version and build numbers enableViewStateAnnotationsboolean <optional>
false Enables view state annotations (double clicking a sticky annotation will reset the viewer to the state it was in when the annotation was created) uiPathstring <optional>
Path to UI folder to use a different UI or customized UI. Default is'./ui/index.html'. notesInLeftPanelboolean <optional>
false If true then it moves the notes panel into a tab inside the left panel selectAnnotationOnCreationboolean <optional>
false If true then newly added annotations will be selected automatically highContrastModeboolean <optional>
false If true then the UI will use high contrast colors to help with accessibility. documentXFDFRetrieverCore.DocumentViewer.DocumentXFDFRetriever <optional>
null The XFDF retriever that will be called when a document is being loaded. The retriever should return a Promise which should resolve to the XFDF string that is going to merged into the document streamingboolean <optional>
A boolean indicating whether to use http or streaming PartRetriever, it is recommended to keep streaming false for better performance. https://docs.apryse.com/documentation/web/guides/streaming-option/. additionalTranslationsobject <optional>
An object to add/edit additional translations data for a specific language Properties
Name Type Description languagestring The language code for which you want to add/edit translation data translationsobject A key/value object with the new/updated translations Properties
Name Type Description keystring A key value for the new/updated translation. Refer to the lib/ui/i18n folder to find the existing keys in the translation files valuestring A value of the new/updated translation disableIndexedDBboolean <optional>
false If true than the usage of indexedDB will be disabled for webviewer **Multi-tab Only**. autoExpandOutlinesboolean <optional>
If set to true, will expand outlines by default. enableAnnotationNumberingboolean <optional>
If set to true, as annotations are imported/created they will each be numbered. Starting at 1, each annotation will be assigned the next greatest available number. enableOfficeEditingboolean <optional>
If true, will load docx files with editing capabilities. disableMultiViewerComparisonboolean <optional>
false If true then MultiViewerMode will not show compare overlay annotations. disableObjectURLBlobsboolean <optional>
false If true, then uncompressed JavaScript files will be loaded without instantiating a Blob. If false, then the URL.createObjectUrl API will be used to instantiate an uncompressed Blob instance of the appropriate PDF worker file (Note that this goes against the Content-Security-Policy (CSP) rule "script-src blob:"). uistring <optional>
default Type of UI to be used. Accepts `default`|`beta`. Toggle the beta UI to check out the new modular UI. -
WorkerTypes
-
Used to preload workers before a document has been loaded.
Properties:
Name Type Description PDFstring To preload the PDF worker object OFFICEstring To preload the Office worker object LEGACY_OFFICEstring To preload the Legacy Office worker object CONTENT_EDITstring To preload the content edit worker object OFFICE_EDITORstring To preload the office editor worker object ALLstring To preload all the workers objects Example
WebViewer({ preloadWorker: `${WebViewer.WorkerTypes.PDF},${WebViewer.WorkerTypes.OFFICE}` }) .then(function(instance) { ... });