Module: @pdftron/webviewer-html

This is an addon for WebViewer that allows loading HTML web pages so that HTML pages can be annotated. See the npm package on @pdftron/webviewer-html for more information.

Methods


<async, static> initializeHTMLViewer(instance [, options])

Initializes the HTML viewer so that webviewer can load HTMLs.

Parameters:
Name Type Argument Description
instance Object

The WebViewer instance

options Object <optional>

The options objects containing license.

Properties
Name Type Argument Description
license string <optional>

A string containing a license key for WebViewer HTML Addon to remove the watermark.

Returns:

A promise that resolves to an object containing the functions needed to load HTML in WebViewer.

Type
HTMLFunctions

Type Definitions


HTMLFunctions

Type:
  • Object
Properties:
Name Type Description
loadHTMLPage function

Loads an HTML page for the WebViewer instance passed into initializeHTMLViewer.

setInstance function

Sets the WebViewer instance. Must be called if instance is not passed into initializeHTMLViewer


loadHTMLPage(options)

Loads an HTML page for the WebViewer instance passed into initializeHTMLViewer.

Parameters:
Name Type Description
options Object

The options objects containing page iframeUrl, width, height and urlToProxy.

Properties
Name Type Argument Description
iframeUrl string

URL of the page being displayed in webviewer. This should be the url of the proxy server.

width number

Width for the page to be loaded at.

height number

Height for the page to be loaded at.

urlToProxy string

Original URL of the page you are trying to load and that is being proxied by the server.

scrollable boolean <optional>

Boolean containing value for whether or not page should be scrolled.

disableLinkAnnotations boolean <optional>

Boolean containing value for disabling link annotations.

Returns:
Type
void
Example
WebViewer(
      {
        path: 'lib',
      },
      document.getElementById('viewer')
    ).then(async (instance) => {
      // Extends WebViewer to allow loading HTML5 files from URL or static folder.
      const { loadHTMLPage } = await initializeHTMLViewer(instance, { license });

      loadHTMLPage({
        // Your webviewer-html-proxy-server url
        iframeUrl: 'http://localhost:3100/',
        // Original url that is being proxied
        urlToProxy: 'https://www.pdftron.com/',
        width: 500,
        height: 500,
      });
    });

setInstance(instance)

Sets the WebViewer instance. Must be called if instance is not passed into initializeHTMLViewer

Parameters:
Name Type Description
instance Object

The WebViewer instance.

Returns:
Type
void
Example
WebViewer(
      {
        path: 'lib',
      },
      document.getElementById('viewer')
    ).then(async (instance) => {
      // Extends WebViewer to allow loading HTML5 files from URL or static folder.
      const { loadHTMLPage, setInstance } = await initializeHTMLViewer(instance, { license });

      // OR
      // setInstance(instance);
    });

Events


proxyLoaded

Event emitted when the proxy iframe finishes loading. This event comes from the DOMContentLoaded event attached to the proxy website.

Example
WebViewer(...)
    .then((instance) => {
      const { docViewer } = instance;
      docViewer.addEventListener('proxyLoaded', listener);
    });