Helper APIs

Helper APIs are related to WebViewer state or actions.

linkaddSearchListener(listener)

Adds a listener function to be called when search is completed.

Parameters

  • listener (function) - Listener function that will be triggered when search completed. The function will receive the following parameters:

    • searchValue (string) - Search value
    • options (object) - Search options object, which includes caseSensitive, wholeWord, wildcard and regex
    • results (array of objects) - Search results

Returns

  • N/A

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  const searchListener = (searchValue, options, results) => { ... };
  viewerInstance.addSearchListener(searchListener);
});

linkcloseDocument()

Closes the document that's currently opened

Parameters

  • N/A

Returns

  • Promise

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.closeDocument().then(() => {
    console.log('Document is closed');
  });
});

linkdownloadPdf(includeAnnotations)

Downloads the pdf document with or without annotations added by WebViewer UI.

Parameters

  • includeAnnotations (boolean) - Whether or not to include annotations added by WebViewer UI. Default is true.

Returns

  • N/A

Example

// download pdf without annotations added by WebViewer UI
$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.downloadPdf(false);
});

linkenableAnnotations(enable)

Enables/disables annotations feature, affecting the annotation visibility and elements related to annotations.

Parameters

  • enable (boolean) - Whether or not to enable annotations feature. Default is true.

Returns

  • N/A

Example

// disable annotations feature
$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.enableAnnotations(false);
});

linkenableFilePicker(enable)

Enables/disables file picker feature, affecting the Open files button in menu overlay and shortcut to open local files (ctrl/cmd + o).

Parameters

  • enable (boolean) - Whether or not to enable file picker feature. Default is true.

Returns

  • N/A

Example

// enable file picker feature
$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.enableFilePicker();
});

linkenableNotesPanel(enable)

Enables/disables notes panel feature, affecting any elements related to notes panel.

Parameters

  • enable (boolean) - Whether or not to enable notes panel feature. Default is true.

Returns

  • N/A

Example

// disable notes panel feature
$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.enableNotesPanel(false);
});

linkenableTextSelection(enable)

Enables/disables text to be selected in the document.

Parameters

  • enable (boolean) - Whether or not to enable text selection feature. Default is true.

Returns

  • N/A

Example

// disable text to be selected in the document
$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.enableTextSelection(false);
});

linkexecuteSearch(searchValue[, options])

Execute search from the WebViewer UI.

Parameters

  • searchValue (string) - Search value.
  • options (object, optional) - Search options with following parameters:

    • caseSensitive (boolean) - Option to search with matching cases.
    • wholeWord (boolean) - Option to search whole words only.
    • wildcard (boolean) - Option to search a string with a wildcard *. For example, *viewer.
    • regex (boolean) - Option to search for a regex string. For example, www(.*)com.

Returns

  • N/A

Example

// search for string 'test', and match whole words only
$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.executeSearch('test', { wholeWord: true });
});

linkgetAnnotationUser()

Return the current user name

Parameters

  • N/A

Returns

  • Username (string)

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  console.log(viewerInstance.getAnnotationUser());
});

linkgetToolMode()

Return the current tool.

Parameters

  • N/A

Returns

  • Object with fields toolName (string) and toolObject (object)

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  console.log(viewerInstance.getToolMode().toolName, viewerInstance.getToolMode().toolObject);
});

linkgetZoomLevel()

Return the current zoom level

Parameters

  • N/A

Returns

  • Zoom level (number)

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  console.log(viewerInstance.getZoomLevel());
});

linkisAdminUser()

Returns whether the current user is admin.

Parameters

  • N/A

Returns

  • isAdmin (boolean)

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  console.log(viewerInstance.isAdminUser());
});

linkisReadOnly()

Returns whether the current mode is read only.

Parameters

  • N/A

Returns

  • isReadOnly (boolean)

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  console.log(viewerInstance.isReadOnly());
});

linkloadDocument(documentPath[, options])

Load a document inside WebViewer UI.

Parameters

  • documentPath (string or fileObject) - Path to the document OR file object if opening local file.
  • options (object, optional) - Object with following parameters:

    • documentId (string) - Unique id of the document.
    • filename (string) - Filename of the document, which is used when downloading the PDF.

Returns

  • N/A

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.loadDocument('/path/to/document.pdf', { documentId: '1', filename: 'sample-1' });
});

linkregisterTool(obj)

Registers tool in the document viewer tool mode map, and adds a button object to be used in the header.

Parameters

  • obj (object) - An object containing the followings:

    • toolName (string) - Name of the tool.
    • toolObject (string) - Instance of the tool. For more information about creating a custom tool object, refer to Customizing tools.
    • buttonImage (string) - Path to an image or base64 data for the tool button.
    • buttonName (string, optional) - Name of the tool button that will be used in data-element.
    • buttonGroup (string, optional) - Path to an image or base64 data.

Returns

  • N/A

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.registerTool({
    toolName: 'MyTool',
    toolGroup: 'miscTools',
    toolObject: myCustomTool,
    buttonImage: 'path/to/image',
    buttonName: 'myToolButton',
  });
});

linkremoveSearchListener(listener)

Removes the search listener function.

Parameters

  • listener (function) - Search listener function that was added.

Returns

  • N/A

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  const searchListener = (searchValue, options, results) => { ... };
  viewerInstance.addSearchListener(searchListener);
  viewerInstance.removeSearchListener(searchListener);
});

linksaveAnnotations()

Saves the annotations to the serverUrl specified in the constructor options using a POST request.

Parameters

  • N/A

Returns

  • N/A

Example

// saves the annotation to serverUrl
$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.saveAnnotations();
});

linksetAdminUser(isAdmin)

Sets the current user to be admin or not. Admin users have permission to edit/delete any annotations, including the ones they didn't create.

Parameters

  • isAdmin (boolean) - Whether or not to set the current user to be an admin.

Returns

  • N/A

Example

// sets the current user to be an admin
$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.setAdminUser(true);
});

linksetAnnotationUser(username)

Sets name of the current user

Parameters

  • username (string) - Username to be used for current user.

Returns

  • N/A

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.setAnnotationUser('Guest-1');
});

linksetReadOnly(isReadOnly)

Sets the WebViewer UI to be a read only mode. In read only mode, users cannot create/edit annotations.

Parameters

  • isReadOnly (boolean) - Whether or not to set the WebViewer UI to be in in read only mode.

Returns

  • N/A

Example

// sets the viewer to read only mode
$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.setReadOnly(true);
});

linksetToolMode(toolName)

Sets tool mode.

Parameters

  • toolName (string) - Name of the tool, which is either the key from toolModeMap or the name you registered your custom tool with. For custom tool registration, refer to registerTool.

Returns

  • N/A

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.setToolMode('AnnotationEdit');
});

linksetZoomLevel(zoomLevel)

Sets zoom level.

Parameters

  • zoomLevel (number or string) - Zoom level in either number or percentage.

Returns

  • N/A

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.setZoomLevel('150%'); // or setZoomLevel(1.5)
});

linkunregisterTool(toolName)

Unregisters tool in the document viewer tool mode map, and removes the button object.

Parameters

  • toolName (string) - Name of the tool.

Returns

  • N/A

Example

$(viewerElement).on('ready', () => {
  const viewerInstance = viewer.getInstance();
  viewerInstance.unregisterTool('MyTool');
});