@pdftron/webviewer-html
Version:
This is an addon for WebViewer that allows loading HTML web pages so that they can be annotated.
133 lines (130 loc) • 5.12 kB
TypeScript
import type { WebViewerInstance } from '@pdftron/webviewer';
export type PageData = {
iframeUrl: string;
width: number;
height: number;
urlToProxy: string;
scrollable?: boolean;
disableLinkAnnotations?: boolean;
};
export type HTMLViewerOptions = {
license?: string;
};
export type IFrame = HTMLIFrameElement;
export type HTMLPage = {
page: PageData;
};
export type WebViewerHTMLInstance = {
/**
* @callback loadHTMLPage
* @param {Object} options - The options objects containing page iframeUrl, width, height and urlToProxy.
* @property {string} options.iframeUrl
* URL of the page you are trying to load
* @property {number} options.width
* Width for the page to be loaded at.
* @property {number} options.height
* Height for the page to be loaded at.
* @property {string} options.urlToProxy
* URL that is being proxied
* @property {boolean} [options.scrollable]
* Boolean containing value for whether or not page should be scrolled.
* @property {boolean} [options.disableLinkAnnotations]
* Boolean containing value for disabling link annotations.
*/
loadHTMLPage: (options: PageData) => void;
/**
* Sets the WebViewer instance. Must be called if instance is not passed into initializeHTMLViewer
* @callback setInstance
* @param {Object} instance The WebViewer instance.
*/
setInstance: (instance: WebViewerInstance) => void;
};
/**
* This is an addon for WebViewer that allows loading HTML web pages so that HTML pages can be annotated.
* See the npm package on {@link https://www.npmjs.com/package/@pdftron/webviewer-html @pdftron/webviewer-html} for more information.
* @module @pdftron/webviewer-html
*/
/**
* Event emitted when the proxy iframe finishes loading.
* This event comes from the DOMContentLoaded event attached to the proxy website.
*
* @event proxyLoaded
* @example
WebViewer(...)
.then((instance) => {
const { docViewer } = instance;
docViewer.addEventListener('proxyLoaded', listener);
});
*/
/**
* @typedef {Object} HTMLFunctions
* @property {function} loadHTMLPage
* Loads an HTML page for the WebViewer instance passed into initializeHTMLViewer.
* @property {function} setInstance
* Sets the WebViewer instance. Must be called if instance is not passed into initializeHTMLViewer
*/
/**
* Loads an HTML page for the WebViewer instance passed into initializeHTMLViewer.
* @callback loadHTMLPage
* @param {Object} options - The options objects containing page iframeUrl, width, height and urlToProxy.
* @param {string} options.iframeUrl
* URL of the page being displayed in webviewer. This should be the url of the proxy server.
* @param {number} options.width
* Width for the page to be loaded at.
* @param {number} options.height
* Height for the page to be loaded at.
* @param {string} options.urlToProxy
* Original URL of the page you are trying to load and that is being proxied by the server.
* @param {boolean} [options.scrollable]
* Boolean containing value for whether or not page should be scrolled.
* @param {boolean} [options.disableLinkAnnotations]
* Boolean containing value for disabling link annotations.
* @returns {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,
});
});
*/
/**
* Sets the WebViewer instance. Must be called if instance is not passed into initializeHTMLViewer
* @callback setInstance
* @param {Object} instance The WebViewer instance.
* @returns {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);
});
*/
/**
* Initializes the HTML viewer so that webviewer can load HTMLs.
* @static
* @alias module:@pdftron/webviewer-html.initializeHTMLViewer
* @param {Object} instance The WebViewer instance
* @param {Object} [options] - The options objects containing license.
* @param {string} [options.license] - A string containing a license key for WebViewer HTML Addon to remove the watermark.
* @returns {HTMLFunctions} A promise that resolves to an object containing the functions needed to load HTML in WebViewer.
*/
declare const initializeHTMLViewer: (instance?: WebViewerInstance, options?: HTMLViewerOptions) => Promise<WebViewerHTMLInstance>;
export { initializeHTMLViewer };