1. Home
  2. Foxit PDF SDK for Web
  3. Developer Guide for Foxit PDF SDK for Web

Developer Guide for Foxit PDF SDK for Web

Foxit PDF SDK for Web Overview

By using Foxit PDF SDK for Web, developers can deploy and customize a Foxit PDF SDK for Web that supports viewing PDF documents within a web browser. Integrating a Foxit PDF SDK for Web into a zero-footprint web app allows end users to view PDF documents on desktop and mobile devices without installing anything.

Why Foxit PDF SDK for Web is your choice

Foxit is an Amazon-invested leading software provider of solutions for reading, editing, creating, organizing, and securing PDF documents. Foxit PDF SDK for Web is a cross-platform solution for PDF online viewing. Foxit PDF SDK for Web enterprise edition has been chosen by many of the world’s leading firms for integration into their solutions. Customers choose this product for the following reasons:

  • Fully customizable
    Developers can easily design a unique style for their Foxit PDF SDK for Web interface, and make it consistent to their web applications.
  • Easy to integrate
    Developers can easily reference Foxit PDF SDK for Web by referring to resource files and writing a small amount of code to display and edit PDF files, and have a wealth of interfaces to connect users and user data.
  • Standard and consistent annotation data
    The annotations in Foxit PDF SDK for Web are consistent when viewing and editing in other applications.
  • Powered by Foxit’s high fidelity rendering PDF engine
    The core technology of Foxit PDF SDK for Web is based on Foxit’s PDF engine, which is trusted by a large number of well-known companies. Foxit’s powerful engine makes document viewing fast and consistent in all environments.

In addition, Foxit’s products are offered with the full support of our dedicated support engineers if support and maintenance options are purchased. Updates are released on a regular basis. Foxit PDF SDK for Web will be the most cost-effective choice if you want to develop a cross-platform PDF document viewing solution that can control document distribution.

Audience and Scope

This document is primarily intended for developers who need to integrate the Foxit PDF SDK for Web into their web applications. It includes the direct reference examples as well as custom front-end APIs for customization.

Your Web Application

Foxit PDF SDK for Web provides a solution that enables a web application to view PDFs seamlessly without any plugins or local applications. Developers should prepare a PDF hosting server like Nginx or XAMP and do the usual configuration before using Foxit PDF SDK for Web.

Evaluation

Foxit PDF SDK for Web allows users to download the trial version to evaluate the SDK. The trial version is the same as the standard version except for the 30-day limitation for free trial and the trial watermarks in the generated pages. After the evaluation period expires, customers should contact the Foxit sales team and purchase licenses to continue using Foxit PDF SDK for Web.

License

Developers are required to purchase licenses to use Foxit PDF SDK for Web in their solutions. Licenses grant users permission to release their applications based on Foxit PDF SDK for Web. However, users are prohibited to distribute any documents, sample codes, or source codes in the released packages of Foxit PDF SDK for Web to any third party without the permission from Foxit Software Incorporated.

Getting Started

Foxit PDF SDK for Web provides multi-level and rich features and interfaces which include the API without UI, simple UI rendering, UI customization, as well as application of complex UI interactions. This following sections introduces the package structure, demos, and how to run the demos.

Understanding the Package Structure

Package structure description

Download the “FoxitPDFSDKForWeb_7_0_0.zip” package, and extract it to a new directory like “FoxitPDFSDKForWeb” as shown below. The package contains:

docs – A folder containing API references, developer guide.
samples – A folder containing demos for Foxit PDF SDK for Web.
libs – A folder containing the source packages for SDK core libraries.
server – A folder containing http-server and the Node.js scripts for snapshot server.
legal.txt – Legal and copyright information.
package.json – Project description file.

In the “lib” folder, it contains the files as follows:

Libs FolderDescription
jr-engineA folder containing front-end rendering engine.
localesA folder containing the internationalized entries data. The entries for different languages is placed in different directories by name.
PDFViewCtrlA folder containing the plugins for PDFViewCtrl.
stampsStamps templates.
uix-addonsA folder containing the plugins for UIExtension.
PDFViewCtrl.cssThe CSS of the simple UI for SDK library.
PDFViewCtrl.full.jsThe SDK library with simple UI.
PDFViewCtrl.jsThe PDFViewCtrl library without third-party libraries.
PDFViewCtrl.vendor.jsThe third-party libraries used by PDFViewCtrl (See the lists later).
PDFViewCtrl.polyfills.jsThe script files that PDFViewCtrl relies on, used to be compliant with different browsers.
UIExtension.cssThe CSS of the UI for all the features.
UIExtension.full.jsThe full-featured SDK library.
UIExtension.jsThe UIExtension library without third-party libraries
UIExtension.vendor.jsThe third-party libraries used by UIExtension (See the lists later)
UIExtension.polyfills.jsThe script files that UIExtension relies on, used to be compliant with different browsers.
WebPDFJRWorker.jsThe script files running in the Web Worker, which are used for calling the front-end rendering engine.

Package.json

Foxit PDF SDK for Web provides a package.json file to help developers to quickly experience the SDK product, and make it easier to be integrated into their project. The content is as follows:

{
 "name": "foxit-pdf-sdk-for-web",
 "version": "7.0.0",
 "description": "Foxit pdf sdk for web.",
 "author": "Foxit Software Inc.",
 "main": "./lib/PDFViewCtrl.full.js",
 "scripts": {
 "start": "concurrently --kill-others \"npm run start-http-server\" \"npm run start-snapshot-server\"",
 "start-snapshot-server": "node ./server/snapshot/src/index -p 3002",
 "start-http-server": "node ./server/index",
 "postinstall": "npm start"
 },
 "devDependencies": {
 "chalk": "^2.4.1",
 "concurrently": "^4.1.0",
 "http-proxy-middleware": "^0.19.1",
 "koa": "^2.7.0",
 "koa-body": "^4.0.4",
 "koa-body-parser": "^1.1.2",
 "koa-router": "^7.4.0",
 "koa2-connect": "^1.0.2",
 "lru-cache": "^4.1.3",
 "raw-body": "^2.3.3",
 "require-dir": "^1.0.0",
 "serve-handler": "^6.0.2"
 },
 "serve": {
 "port": 8080,
 "public": "/",
 "proxy": {
 "target": "http://127.0.0.1:3002",
 "changeOrigin": true
 }
 }
}

The third-party libraries used in Foxit PDF SDK for Web

Foxit PDF SDK for Web provides two formats of packages: the package with the third-party libraries, and the package without the third-party libraries. If your project has already used the same third-party libraries, you don’t need to add it for avoiding duplication.

For PDFViewCtrl.full.js package:

PDFViewCtrl.full.js – The SDK library with simple UI
PDFViewCtrl.js – The PDFViewCtrl library without third-party libraries
PDFViewCtrl.vendor.js – The third-party libraries used by PDFViewCtrl (See the lists later)

So that, PDFViewCtrl.js plus PDFViewCtrl.vendor.js is equal to PDFViewCtrl.full.js.

The following two forms are equivalent:

<script src="../FoxitPDFSDKForWeb/lib/PDFViewCtrl.full.js"></script>
<script src="../FoxitPDFSDKForWeb/lib/PDFViewCtrl.vendor.js"></script>
<script src="../FoxitPDFSDKForWeb/lib/PDFViewCtrl.js"></script>

The PDFViewCtrl.vendor.js contains the following third-party libraries:

  • jQuery
  • i18next
  • i18nextChainedBackend
  • i18nextLocalStorageBackend
  • i18nextXHRBackend
  • dialogPolyfill
  • Hammer
  • EventEmitter

For UIExtension.full.js package:

UIExtension.full.js – The full-featured SDK library
UIExtension.js – The UIExtension library without third-party libraries
UIExtension.vendor.js – The third-party libraries used by UIExtension (See the lists later)

So that, UIExtension.js plus UIExtension.vendor.js is equal to UIExtension.full.js.

The following two forms are equivalent:

<script src="../FoxitPDFSDKForWeb/lib/UIExtension.full.js"></script>
<script src="../FoxitPDFSDKForWeb/lib/UIExtension.vendor.js"></script>
<script src="../FoxitPDFSDKForWeb/lib/UIExtension.js"></script>

The UIExtension.vendor.js contains the following third-party libraries:

  • jQuery
  • i18next
  • i18nextChainedBackend
  • i18nextLocalStorageBackend
  • i18nextXHRBackend
  • dialogPolyfill
  • Hammer
  • EventEmitter

Integration

This section will introduce how to integrate Foxit PDF SDK for Web to your project.

Integrate as a Global Variable

You can integrate the Foxit PDF SDK for Web to your project as a global variable:

<script src="./lib/PDFViewCtrl.full.js"></script>
let PDFViewer = PDFViewCtrl.PDFViewer;
let pdfViewer = new PDFViewer()

Integrate as module

You can integrate the Foxit PDF SDK for Web to your project by module.

ES Modules (ESM)

Configure babelrc:

{
 "presets": ["env", "stage-0"] 
}

Configure webpack loader:

rules: [
 {
 test: /\.js$/,
 loader: 'babel-loader'
 },
 ],

Import the library:

import {PDFViewer} from './FoxitPDFSDKForWeb/lib/PDFViewCtrl.full';
let pdfViewer = new PDFViewer(…)

CommonJS

Import the library:

var PDFViewCtrl = require('./FoxitPDFSDKForWeb/lib/PDFViewCtrl.full');
var pdfviewer = new PDFViewCtrl.PDFViewer(...);

This way of importing of CommonJS is simple, so that it doesn’t need additional configuration of webpack.

AMD

define('your-module-name', ['./FoxitPDFSDKForWeb/lib/PDFViewCtrl.full'],
function(PDFViewerModule) {
var pdfviewer = new PDFViewCtrl.PDFViewer(...);
});

webpack configuration:

module.exports = {
context: __dirname + 'point to the dir your app code is in',
 
entry: 'your entry file path',
output: {
path: 'The path for the output built files',
// ...
},
// It is used to support the older versions of jquery that you might not need. 
amd: {
jQuery: true
},
module: {
// loaders
},
resolve: {
root: [],
alias: {
}
}
};

Convenient dependency import

The above methods all use the relative path when integrating PDFViewCtrl module, but it is not easy to use the relative path to import multiple files. In this case, convenient dependency import might be a good choice. Please follow the steps below.

1. Add npm package declaration “package.json” for the unzipped package of Foxit PDF SDK for Web

lib/package.json:

{
 "name": "foxitwebsdk",
 "version": "7.0.0",
 "description": "",
 "main": "PDFViewCtrl.full.js", // Point to the Foxit PDF SDK for Web library that you need to reference. 
 "scripts": {
 },
}

2. Add the Foxit PDF SDK for Web dependencies in the package.json file of your project

"dependencies": {
 "foxitweb": "file:./FoxitPDFSDKForWeb/lib"
 },

3. Run “npm install” to install the dependencies.

4. Import and use.

  // EMS
import {PDFViewer} from 'foxitweb';
let pdfViewer = new PDFViewer(…);
 
// or CommonJS
var PDFViewCtrl = require('foxitweb');
var pdfviewer = new PDFViewCtrl.PDFViewer(...);

 

Quickly Run Foxit PDF SDK for Web Demo

To run Foxit PDF SDK for Web Demos, you should prepare a web server at first. In this guide, we will introduce the demos and then take the Nginx and Node.js servers as examples to show you how to quickly run Foxit PDF SDK for Web demos.

Introduction to the Demos

In the “examples” folder, it provides multiple demos as references for users. After starting the http server, you can access and experience the demos in the browser by typing the corresponding address.

• A full-featured PDF viewer demo

It is a ready-to-go demo that you can integrate it into your project with all of the featured provided by Foxit PDF SDK for Web. This demo uses the full-featured package “UIExtension.full.js” (in the “lib” folder) including the PDF view and document parsing. You can get the source code of this demo from “examples/UIExtension/advanced_webViewer/index.html”.

In the browser, quickly access the demo at http://localhost:{port}/examples/UIExtension/advanced_webViewer/index.html

• A simple UI demo

It is a simple UI demo that demonstrates how to call Foxit PDF SDK for Web API to load a PDF document, and zoom in/out the document. This demo uses the “PDFViewCtrl.full.js” package in the “lib” folder. You can get the source code of this demo from “examples/PDFViewCtrl/basic_webViewer/index.html”.

In the browser, quickly access the demo at http://localhost:{port}/examples/PDFViewCtrl/basic_webViewer/index.html

• Offline demo

This demo is a sample that demonstrates how to register the “service-worker.js” found in the “examples/PDFViewCtrl/service-worker” folder to better cache the core dependency files “gsdk.js” and font files in a browser supported by the service worker, in order to speed up the file secondary opening or use the offline mode. You can get the source code of this demo from “examples/PDFViewCtrl/service-worker/cache.html “.

In the browser, quickly access the demo at http://localhost:{port}/examples/PDFViewCtrl/service-worker/cache.html

• Inline DIV application demo

This demo renders the simple UI of Foxit PDF SDK for Web to a div container with a specified size. You can get the source code of this demo from “examples/PDFViewCtrl/div/index.html”.

In the browser, quickly access the demo at http://localhost:{port}/examples/PDFViewCtrl/div/index.html

Nginx working sample

Using Windows as an example, assume that Nginx was installed on your system already. When you have Nginx server running, you can directly modify the ‘nginx.conf’ in the conf directory, here we directly write a configuration file to make Foxit PDF SDK for Web Demo run. Please follows the steps below:

1. Download FoxitPDFSDKForWeb_7_0_0.zip.

2. Unzip it to a new folder like “FoxitPDFSDKForWeb” in ‘D:/’ directory for example.

3. Create a Nginx configuration file in a location. For example, create a new ‘webpdf.conf’ file inside ‘D:/FoxitPDFSDKForWeb’.

4. Set up a virtual server and configure a location. The following configuration is an example. The ‘D:/FoxitPDFSDKForWeb/’ is the path to the SDK.

server {
 listen 8080;
server_name 127.0.0.1;
 
 location / {
 alias "D:/FoxitPDFSDKForWeb/";
 charset utf8;
 index index.html;
}
}

5. Locate to the installed path of Nginx, find the ‘nginx.conf’ in the conf directory, use include directive to reference the contents of the new configuration file.

include D:/FoxitPDFSDKForWeb/webpdf.conf;

6) For changes to the configuration file to take effect, you need to restart the nginx server or use ‘nginx -s reload’ to upgrade the configuration without interrupting the processing of current requests.

7) Access the demos in the browser.
For the full-featured PDF viewer demo, please access the page at http://127.0.0.1:8080/examples/UIExtension/advanced_webViewer/index.html.
For the simple UI demo, please access the page at http://127.0.0.1:8080/examples/PDFViewCtrl/basic_webViewer/index.html.

Note: You can run the demo according to the above configuration, but at that time the snapshot feature cannot work correctly. The snapshot cannot be cached to clipboard, so that you cannot paste it to the location as you wish. Please follow the steps below to build the snapshot server:

a) Install node.js 9.0 or higher, if it is already installed, skip it.

b) In a command window, navigate to the root directory (“D:/FoxitPDFSDKForWeb”), type “npm install” to install the required dependencies, and then type “npm run start-snapshot-server” to start the snapshot server (the default port is 3002).

c) Configure Nginx reverse proxy in the ‘webpdf.conf’ file under ‘D:/FoxitPDFSDKForWeb’ folder.

server {
 listen 8080;
server_name 127.0.0.1;
 
 location / {
 alias "D:/FoxitPDFSDKForWeb/";
 charset utf8;
 index index.html;
}
 
location ~ ^/snapshot/(.+)$ {
 proxy_pass http://127.0.0.1:3002/snapshot/$1$is_args$args;
 proxy_redirect off;
 
 proxy_request_buffering on;
 
 proxy_set_header Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

d) Restart Nginx server, and refresh your browser, the snapshot feature can work correctly.

Node.js working sample

Assuming that Node.js 9.0 or higher is available on your system already, follow the steps below to run the Foxit PDF SDK for Web demos:

1. Download FoxitPDFSDKForWeb.zip.

2. Unzip it to a new folder like “FoxitPDFSDKForWeb” in ‘D:/’ directory for example.

3. In the command window, navigate to the above unzipped folder (“D:/FoxitPDFSDKForWeb”), type “npm install ” to install the required dependencies, and then type “npm start” to start http-server.

4. Access the demos in the browser.
For the full-featured PDF viewer demo, please access the page at
http://127.0.0.1:8080/examples/UIExtension/advanced_webViewer/index.html
For the simple UI demo, please access the page at http://127.0.0.1:8080/examples/PDFViewCtrl/basic_webViewer/index.html.

Note: Using this method, you do not need to configure the proxy, the snapshot feature can be used normally. If you want to specify the port as desired, you can change it in the “package.json” file of Foxit PDF SDK for Web package as follows:

"serve": {
 "port": 8080, // You can specify the port as desired.
 "public": "/",
 "proxy": {
 "target": "http://127.0.0.1:3002",
 "changeOrigin": true
 }
}

 

Building a new web project

This section will help you to quickly get started with using Foxit PDF SDK for Web to build a simple PDF viewer and a full-featured PDF viewer with step-by-step instructions provided.

Preparations

Create a new web project

a) Create a new directory as a project folder, such as ‘D:/test_web’.

b) Copy the “lib”, “server” folders and the “package.json” file from Foxit PDF SDK for Web package to ‘D:/test_web’.

c) Copy a PDF file (for example, the demo guide in the package) to ‘D:/test_web’.

d) Create an html file (index.html) in the ‘D:/test_web’ folder. Then the directory structure is:

test_web
+-- lib (copy from the Foxit PDF SDK for Web package)
+-- server (copy from the Foxit PDF SDK for Web package)
+-- package.json (copy from the Foxit PDF SDK for Web package)
 +-- index.html

The whole content of the index.html is:

<html>
<head>
<meta charset="utf-8"/>
<style>
 .fv__ui-tab-nav li span {
 color: #636363;
 }
 .flex-row {
 display: flex;
 flex-direction: row;
 }
 </style>
 <!-- ignore other unimportant code -->
</head>
<body>
</body>
</html>

Start Http-Server

You can refer to section “Nginx working sample” or section “Node.js working sample” to start the http-server. In this project, we set the port to 8899 for example.

Then, access http://127.0.0.1:8899/index.html in the browser, and you will see a blank page, which indicates that the preparations have been completed.

Integrate the simple demo using PDFViewCtrl

This section will describe how to integrate the simple demo using PDFViewCtrl based on the above create project. Just follow the steps below:

a) Import the “PDFViewCtrl.full.js” library found in the “lib” folder:

<script src="./lib/PDFViewCtrl.full.js"></script>

b) In the HTML tag, add the

elements as the web viewer container:

<div id="pdf-viewer"></div>

c) Initialize the Foxit PDF SDK for Web:

var licenseSN = "Your license SN";
 var licenseKey = "Your license Key"; 
 
<script>
 let PDFViewer = PDFViewCtrl.PDFViewer;
 let pdfViewer = new PDFViewer({
 libPath: './lib', // the library path of Web SDK.
 jr: {
 licenseSN: licenseSN,
 licenseKey: licenseKey,
 }
 });
 pdfViewer.init('#pdf-viewer'); // the div (id="pdf-viewer") 
</script><script></script>

Note: The values of licenseSN and licenseKey can be found in the “example/license-key.js” file of Foxit PDF SDK for Web package.

d) Open a PDF document:

// modify the file path as your need.
fetch('/foxitpdfsdkforweb_demo_guide.pdf').then(response => {
 response.arrayBuffer().then(buffer => {
 pdfViewer.openPDFByArrayBuffer(buffer);
 })
})

e) The above steps are the key points of integrating the simple demo to your created project using PDFViewCtrl. After finishing it, refresh your browser (http://127.0.0.1:8899/index.html), and then you can see the demo guide as follows:

Now, it is a simple web PDF viewer, you can zoom in/out the PDF document by right-clicking anywhere on the page to select the zoom in or zoom out options.

The whole content of the index.js is:

<html>
<head>
<meta charset="utf-8"/>
 <style>
 .fv__ui-tab-nav li span {
 color: #636363;
 }
 .flex-row {
 display: flex;
 flex-direction: row;
 }
</style>
 <!-- ignore other unimportant code -->
</head>
<body>
 <div id="pdf-viewer"></div>
 <script src="./lib/PDFViewCtrl.full.js"></script>
 <script>
 var licenseSN = "Your license SN";
 var licenseKey = "Your license Key"; 
 </script>
 <script>
 let PDFViewer = PDFViewCtrl.PDFViewer;
 let pdfViewer = new PDFViewer({
 libPath: './lib', // the library path of Web SDK.
 jr: {
 licenseSN: licenseSN,
 licenseKey: licenseKey,
 }
 });
 pdfViewer.init('#pdf-viewer'); // the div (id="pdf-viewer")
 
 // modify the file path as your need.
 fetch('/foxitpdfsdkforweb_demo_guide.pdf').then(response => {
 response.arrayBuffer().then(buffer => {
 pdfViewer.openPDFByArrayBuffer(buffer);
 })
 })
 </script>
</body>
</html>

The previous section integrates the simple demo using PDFViewCtrl, which is just a simple web PDF viewer. In this section, we will show you how to integrate the full-featured PDF viewer using UIExtension. Just follow the steps below:

a) Add a style (/lib/UIExtension.css) to the tag of the HTML page.

<link rel="stylesheet" type="text/css" href="./lib/UIExtension.css"/>

b) Import the “UIExtension.full.js” library found in the “lib” folder:

<script src="./lib/UIExtension.full.js"></script>

c) In the HTML tag, add the

elements as the web viewer container:

<div id="pdf-ui"></div>

d) Initialize the Foxit PDF SDK for Web:

<script>
 var licenseSN = "Your license SN";
 var licenseKey = "Your license Key"; 
</script>
<script>
 var pdfui = new UIExtension.PDFUI({
 viewerOptions: {
 libPath: './lib', // the library path of web sdk.
 jr: {
 licenseSN: licenseSN,
 licenseKey: licenseKey
 }
 },
 renderTo: '#pdf-ui' // the div (id="pdf-ui").
 });
</script>

Note: The values of licenseSN and licenseKey can be found in the “example/license-key.js” file of Foxit PDF SDK for Web package.

e) Open a PDF document:

// modify the file path as your need.
fetch('/foxitpdfsdkforweb_demo_guide.pdf').then(response => {
 response.arrayBuffer().then(buffer => {
 pdfui.openPDFByArrayBuffer(buffer);
 })
})

f) The above steps are the key points of integrating the full-featured PDF viewer to your created project using UIExtension. After finishing it, refresh your browser (http://127.0.0.1:8899/index.html), and then you can see the demo guide as follows:

Now, it is a full-featured web PDF viewer, you can view/edit/comment/protect the PDF document as desired.

The whole content of the index.js is:

<html>
<head>
 <meta charset="utf-8"/>
 <link rel="stylesheet" type="text/css" href="./lib/UIExtension.css"/>
 <style>
 .fv__ui-tab-nav li span {
 color: #636363;
 }
 .flex-row {
 display: flex;
 flex-direction: row;
 }
 </style>
 <!-- ignore other unimportant code -->;
</head>
<body>
<div id="pdf-ui"<>/div>
 <script src="./lib/UIExtension.full.js"<>/script>
 </script><script>
 var licenseSN = "Your license SN";
 var licenseKey = "Your license Key";
 </script> {
 response.arrayBuffer().then(buffer => {
 pdfui.openPDFByArrayBuffer(buffer);
 })
 })
 
</div></body>
</html>

Integrate the add-ons of UIExtension

Foxit PDF SDK for Web provides some extension features for UIExtension, such as file property, multi-media, password protection, redaction, PDF path objects, and print. To integrate these add-ons, you should add the code snippets below:

addons: [
 './lib/uix-addons/file-property/', // should use the relative path.
 './lib/uix-addons/multi-media/',
 './lib/uix-addons/password-protect/',
 './lib/uix-addons/redaction/',
 './lib/uix-addons/PathObjects/',
 './lib/uix-addons/print/',
 ]
});

Based on the full-featured PDF viewer project, update the index.html as follows:

<html>
<head>
 <meta charset="utf-8"/>
 <link rel="stylesheet" type="text/css" href="./lib/UIExtension.css"/>
 <style>
 .fv__ui-tab-nav li span {
 color: #636363;
 }
 .flex-row {
 display: flex;
 flex-direction: row;
 }
 </style>
 <!-- ignore other unimportant code -->
</head>
<body>
 <div id="pdf-ui"></div>
 <script src="./lib/UIExtension.full.js"></script>
 <script>
 var licenseSN = "Your license SN";
 var licenseKey = "Your license Key";
</script>
 <script>
 var pdfui = new UIExtension.PDFUI({
 viewerOptions: {
 libPath: './lib', // the library path of web sdk.
 jr: {
 licenseSN: licenseSN,
 licenseKey: licenseKey
 }
 },
 renderTo: '#pdf-ui', // the div (id="pdf-ui").
 
 addons: [
 './lib/uix-addons/file-property/', // should use the relative path.
 './lib/uix-addons/multi-media/',
 './lib/uix-addons/password-protect/',
 './lib/uix-addons/redaction/',
 './lib/uix-addons/PathObjects/',
 './lib/uix-addons/print/',
 ]
 });
 
 // modify the file path as your need.
 fetch('/webpdf_demo_guide.pdf').then(response => {
 response.arrayBuffer().then(buffer => {
 pdfui.openPDFByArrayBuffer(buffer);
 })
 })
 </script>
</body>
</html>

Refresh your browser (http://127.0.0.1:8899/index.html), and then you can see a web PDF viewer with the extension features. For example, for the Home tab, the file property and print features has been integrated as follows:

 

Customizing the UI

From version 7.0, Foxit PDF SDK for Web comes with built-in UI design including the feature modules UI, which are implemented using Foxit PDF SDK for Web and are shipped in the UIExtension.js. Furthermore, customizing UI is straightforward. Foxit PDF SDK for Web provides a rich set of APIs for developers to customize and style the appearance of your web viewer.

The user interface of UIExtension consists of two parts: template and fragments. Template is equivalent to the extension of HTML, the components in the template should be declared by tags. Template is used to customize the UI layout (css style, icon, text, and so on) without interactions. Fragments are a set of UI snippets, which can be used to customize the configuration items and interaction logic of the components in the template. Each snippets has an operation type “action” that specifies the action mode (append, prepend, before, after, ext, replace, insert, and remove, the default is ext.) of the snippets. Through these action modes, you can insert, delete, replace and modify the components in the template.

Customize the UI layout using template

Template is mainly used to customize the UI layout of the components. Following will list some examples to demonstrate the usage of template. Please note that all the examples are based on the full-featured PDF viewer project in a previous section.

Create a simple template

A simplest template is as follows:

var pdfui = new UIExtension.PDFUI({
 viewerOptions: {
 libPath: './lib', // the library path of web sdk.
 jr: {
 licenseSN: licenseSN,
 licenseKey: licenseKey
 }
 },
 renderTo: '#pdf-ui', // the div (id="pdf-ui").
 template: `
 <webpdf>
 <viewer></viewer>
 </webpdf>
 `
});

tag listens the document state (open or not) to control enabling or disabling the UI components. If you need these features, you can use other html tags or custom component tags to replace it.

tag is where the PDF contents are rendered. Each template must have a tag. It can be placed anywhere you want, please refer to the examples in the following sections.

Refresh your browser (http://127.0.0.1:8899/index.html), and then you can see a simple PDF web viewer as follows:

Add a new toolbar button

Use tag to add a new toolbar button.

var pdfui = new UIExtension.PDFUI({
 viewerOptions: {
 libPath: './lib', // the library path of web sdk.
 jr: {
 licenseSN: licenseSN,
 licenseKey: licenseKey
 }
 },
 renderTo: '#pdf-ui', // the div (id="pdf-ui").
 template: `
 <webpdf>
 <toolbar>
 <open -file-dropdown></open>
 </toolbar>
 <viewer></viewer>
 </webpdf>
 `
});

Refresh your browser (http://127.0.0.1:8899/index.html), and then you can see the new toolbar button as follows:

Add a new tab page

Use and tags to add a new tab page.

var pdfui = new UIExtension.PDFUI({
 viewerOptions: {
 libPath: './lib', // the library path of web sdk.
 jr: {
 licenseSN: licenseSN,
 licenseKey: licenseKey
 }
 },
 renderTo: '#pdf-ui', // the div (id="pdf-ui").
 template: `
<webpdf>
 <toolbar>
 <tabs>
 <tab title="Home">
 <open -file-dropdown></open>
 </tab>
<tab title="Comment">
 <div class="flex-row">
 <create -strikeout-button></create>
 <create -underline-button></create>
 <create -squiggly-button></create>
 <create -replace-button></create>
 <create -caret-button></create>
 <create -note-button></create>
 </div>
 </tab>
 </tabs>
 </toolbar>
 <viewer></viewer>
</webpdf>
`
});

Refresh your browser (http://127.0.0.1:8899/index.html), and then you can see the new tab page as follows:

Add a sidebar button

Use tag to add a sidebar button.

var pdfui = new UIExtension.PDFUI({
 viewerOptions: {
 libPath: './lib', // the library path of web sdk.
 jr: {
 licenseSN: licenseSN,
 licenseKey: licenseKey
 }
 },
 renderTo: '#pdf-ui', // the div (id="pdf-ui").
 template: `
<webpdf>
 <toolbar>
 <tabs>
 <tab title="Home">
 <open -file-dropdown></open>
 </tab>
 <tab title="Comment">
 <div class="flex-row">
 <create -strikeout-button></create>
 <create -underline-button></create>
 <create -squiggly-button></create>
 <create -replace-button></create>
 <create -caret-button></create>
 <create -note-button></create>
 </div>
 </tab>
 </tabs>
 </toolbar>
 <div class="flex-row">
 <sidebar>
 <bookmark -sidebar-panel></bookmark>
 </sidebar>
 <viewer></viewer>
 </div>
</webpdf>
`
});

Refresh your browser (http://127.0.0.1:8899/index.html), and then you can see the bookmark sidebar as follows:

Built-in layout template

The built-in layout template for Foxit PDF SDK for Web is shown below. You can modify this template directly to customize the UI layout as desired.

<webpdf>
 <toolbar name="toolbar">
 <tabs name="toolbar-tabs">
 <tab title="toolbar.tabs.home.title" name="home-tab">
 <group -list name="home-toolbar-group-list">
 </group><group name="home-tab-group-hand" retain-count="3">
 <hand -button></hand>
 <selection -button></selection>
 <snapshot -button></snapshot>
 </group>
 <group name="home-tab-group-io" retain-count="1" shrink-title="toolbar.more.document.title">
 <open -file-dropdown></open>
 <download -file-button></download>
 <print -button></print>
 </group>
 <group name="home-tab-group-nav" retain-count="3">
 <goto -prev-page-button></goto>
 <goto -next-page-button></goto>
 <goto -page-input></goto>
 </group>
 <group name="home-tab-group-zoom">
 <zoom -out-button></zoom>
 <zoom -in-button></zoom>
 <editable -zoom-dropdown></editable>
 </group>
 <group name="home-tab-group-page" retain-count="2">
 <continuous -page-button></continuous>
 <continuous -facing-page-button></continuous>
 </group>
 <group name="home-tab-group-magnifier">
 <loupe -tool-button></loupe>
 </group>
 <group name="home-tab-group-marquee">
 <marquee -tool-button></marquee>
 </group>
 
 </tab>
 <tab title="toolbar.tabs.comment.title" name="comment-tab">
 <group -list name="comment-toolbar-group-list">
 </group><group name="comment-tab-group-hand" retain-count="3">
 <hand -button></hand>
 <selection -button></selection>
 <zoom -dropdown></zoom>
 </group>
 <group name="comment-tab-group-mark">
 <create -text-highlight-button></create>
 <create -strikeout-button></create>
 <create -underline-button></create>
 <create -squiggly-button></create>
 <create -replace-button></create>
 <create -caret-button></create>
 </group>
 <group name="comment-tab-group-text">
 <create -note-button></create>
 <create -typewriter-button></create>
 <create -callout-button></create>
 <create -textbox-button></create>
 </group>
 <group name="comment-tab-group-drawing">
 <create -drawings-dropdown></create>
 <create -pencil-button></create>
 <eraser -button></eraser>
 <create -area-highlight-button></create>
 </group>
 <group name="comment-tab-group-measurement">
 <create -distance-button></create>
 </group>
 <group name="comment-tab-group-media">
 <create -attachment-button></create>
 <create -image-button></create>
 <create -link-button></create>
 </group>
 <group name="comment-tab-group-inksign" visible='false'></group>
 <group name="comment-tab-group-stamp">
 <stamp -dropdown></stamp>
 </group>
 <group name="comment-tab-group-other" visible='false'></group>
 
 </tab>
 <tab title="toolbar.tabs.edit.title" name="edit-tab" visible="true">
 <group -list name="edit-toolbar-group-list">
 </group><group name="edit-tab-group-hand" retain-count="3">
 <hand -button></hand>
 <selection -button></selection>
 <zoom -dropdown></zoom>
 </group>
 <group name="edit-tab-group-mode">
 <add -image-button></add>
 </group>
 <group name="edit-tab-group-font" visible="false"></group>
 <group name="edit-tab-group-layer" visible="false"></group>
 <group name="edit-tab-group-redact" visible="false"></group>
 
 </tab>
 <tab title="toolbar.tabs.protect.title" name="protect-tab" visible="true">
 <group -list name="protect-toolbar-group-list">
 </group><group name="protect-tab-group-hand" retain-count="3">
 <hand -button></hand>
 <selection -button></selection>
 <zoom -dropdown></zoom>
 </group>
 <group name="protect-tab-group-sign">
 <ink -sign-dropdown></ink>
 </group>
 
 </tab>
 </tabs>
 </toolbar>
 <div class="fv__ui-body">
 <sidebar name="sidebar" @controller="sidebar:SidebarController">
 <bookmark -sidebar-panel></bookmark>
 <commentlist -sidebar-panel></commentlist>
 <thumbnail -sidebar-panel></thumbnail>
 <layer -sidebar-panel></layer>
 <search -sidebar-panel></search>
 <attachment -sidebar-panel></attachment>
 </sidebar>
 <distance:ruler -container name="pdf-viewer-container-with-ruler">
 <slot>
 <viewer @zoom-on-wheel></viewer>
 </slot>
 </distance:ruler>
 </div>
 <template name="template-container">
 <create -stamp-dialog></create>
 <print -dialog></print>
 <loupe -tool-dialog></loupe>
 <create -ink-sign-dialog></create>
 <measurement -popup></measurement>
 </template>
</webpdf>

Customize the UI using fragments

Fragments are a set of UI snippets. It can be used to customize the configuration items and interaction logic of the components in the template.

Create a new drop-down menu item

The sample code below creates a new drop-down menu including two drop-down buttons, and append it to the end of the group component with the name of “home-tab-group-hand”.

var pdfui = new UIExtension.PDFUI({
 viewerOptions: {
 libPath: './lib', // the library path of web sdk.
 jr: {
 licenseSN: licenseSN,
 licenseKey: licenseKey
 }
 },
 renderTo: '#pdf-ui', // the div (id="pdf-ui").
 
 fragments: [{
 // Add a component to the end of the list of children of a specified target component.
 action: UIExtension.UIConsts.FRAGMENT_ACTION.APPEND,
 // Specify the name of the target component that the new components defined in the above template will be appended to. All the target names of fragments are defined in the layout template.
 target: 'home-tab-group-hand',
 // Define the properties of the added component, such as icon, text, and css style.
 template: `
 <dropdown icon-class="fv__icon-toolbar-shape">
 </dropdown><dropdown -button name="show-hello-button" icon-class="fv__icon-toolbar-hand">say hello</dropdown>
 <dropdown -button name="select-pdf-file-button" accept=".pdf" file-selector icon-class="fv__icon-toolbar-open">open</dropdown>
 
 `,
 // Define the interaction logic of the added component.
 config: [{
 // specify the component in the above template that the configuration will be applied to.
 // For example, the configuration will be applied to the component with the name of "show-hello-button".
 target: 'show-hello-button',
 callback: function () {
 alert('hello');
 }
 },
 {
 // The configuration will be applied to the component with the name of "select-pdf-file-button" which is defined in the above template of fragments.
 target: 'select-pdf-file-button',
 // Extend Controller, and implement the handle function.
 callback: class extends UIExtension.Controller {
 // the lifecycle method: mounted. It will be called after appending the component into the DOM tree.
 mounted() {
 // Get the component mounted by the current Controller instance
 console.info(this.component, 'mounted');
 }
 handle(selectedFile) {
 alert(selectedFile.name);
 }
 }
 }]
 }]
});

Refresh your browser (http://127.0.0.1:8899/index.html), and then you can see a new created drop-down menu as follows:

Delete a toolbar button

To delete a toolbar button through fragment is fairly simple. For example, to delete the Hand tool, you only need to add a new object to the fragment. Based on the above section, add the code below:

{
 target: 'hand-tool',
 action: UIExtension.UIConsts.FRAGMENT_ACTION.REMOVE
}

Refresh your browser (http://127.0.0.1:8899/index.html), and then you can see the Hand tool has been removed from the group component as follows:

Modify a toolbar button

To modify a toolbar button through fragment is also fairly simple. Just like Delete a toolbar button, you only need to add a new object to the fragment.

Change icon of a button

For example, to change the icon of the Hand tool, just add the code below based on the example from the section above “Create a new drop-down menu item”.

{
 target: 'hand-tool',
 config: {
 iconCls: 'fv__icon-toolbar-note' // your custom icon.
 }
}

Refresh your browser (http://127.0.0.1:8899/index.html), and then you can see the icon of the Hand tool has been changed as follows:

 

Change the tooltip of a button

For example, to change the tooltip of the Hand tool , just add the code below based on the section “Create a new drop-down menu item”:

{
 target: 'hand-tool',
 config: {
 tooltip: {
 title: 'your custom tooltip'
 }
 }
}

Refresh your browser (http://127.0.0.1:8899/index.html), and then you can see the tooltip of the Hand tool has been changed to “your custom tooltip” as follows:

Change the event of a button

To change the event of a button, there are two ways:

a) Overwrite the built-in event. For example:

{
 target: 'hand-tool',
 config: {
 callback: function() {
 alert('your click event handler');
 }
 }
}

b) Add custom behavior based on the built-in event (original logic). You can configure the button using the method as follows:

{
 target: 'hand-tool',
 config: {
 callback: {
 before: function(...handleMethodArguments) {
 console.info('called before handle callback with arguments: ', handleMethodArguments);
 },
 after: function(value, ...handleMethodArguments) {
 console.info('called after handle callback with returning value and arguments: ',value, args );
 }
 }
 }
}

Modularization

In order to differentiate the built-in components and user-defined components to avoid conflicts, UIExtension provides modularization feature, which allows you to register the components in different modules separately. Then, you only need to add the prefix of the module name when you declare the components in the template.

For example, the following code creates a new module “my-module”, and registers the user-defined component “MyWidget” in this module:

// Create a new module. Please note that the second parameter must be an array if you create a new module.
var module = UIExension.modular.module('my-module', []);
class MyWidget extends UIExtension.Component {
 static getName() {
 return 'my-widget'; // Declare the tag name of the component.
 }
 render() {
 super.render();
 this.element.innerText = 'my widget';
 }
}
module.registerComponent(MyWidget);

Use the user-defined component:

var pdfui = new UIExtension.PDFUI({
 // Omit other parameters.
 fragments: [{
 action: UIExtension.UIConsts.FRAGMENT_ACTION.APPEND,
 target: 'home-tab-group-hand',
 template: '<my -module:my-widget></my>' // use a colon to separate the module name and component name in the template.
 }]
});

Understanding the built-in components

In simple terms, a tag defined in the template is a component. Container and Widget also belong to the component. The different is that container can hold subcomponents, but widget cannot. All of the native HTML tags are defined as container components, so you can freely nest them.

Foxit PDF SDK for Web has already wrapped a rich set of built-in components for developers to quickly build a web viewer, and customize it as desired. This section will list and introduce the basic components and business components.

Basic components

Business components

 

Implementing Annotation Real-time collaboration

Foxit PDF SDK for Web supports annotation real-time collaboration which means when two browsers are opening a same PDF document, if one browser adds an annotation event, the event will be added synchronization to the other browser. This section will introduce how to implement annotation real-time collaboration using Foxit PDF SDK for Web.

Device requirement

  • Two browser terminals
  • A host with http-server (to handle network events and distribution)
  • Foxit PDF SDK for Web 7.0

Development process for implementing annotation real-time collaboration

To implement annotation real-time collaboration, please refer to the steps below:

1. Initialize the Foxit PDF SDK for Web. Please refer to step c) in the section “Integrate the simple UI demo to your project”.

2. Add the “annotation-add” events as below:

  pdfViewer.eventEmitter.on('annotation-add',(annotations)=>{
 // annotations : the newly added annotations
 var xmlHttp = new XMLHttpRequest();
 let url = 'url/to/post/added/annots'
 xmlHttp.open('POST', url, true);
 
 let formData = new FormData();
 
 let annotJsons =[]
 annotations.map(ele=>{
 annotJsons.push(ele.exportToJSON());
 })
 formData.append('annots',annotJsons)
 xmlHttp.send(formData);
 // handle loaded event.
 })

3. Pull the server distribution event at a regular time.

setInterval(() => {
 var xmlHttp = new XMLHttpRequest();
 let url = 'url/to/get/added/annots'
 xmlHttp.open('GET', url, true);
 xmlHttp.send(null);
 
 xmlHttp.onload = (e) => {
 if (xhr.readyState === 4) {
 if (xhr.status === 200) {
 // Assuming that directly returns the JSON data of the annotations.
 let annotsJson = xmlHttp.response;
 pdfViewer.getCurrentPDFDoc().getPageByIndex(annotsJson.pageIndex).then(page => {
 annotsJson.annots.map(annotJSON => {
 page.addAnnot(annotJSON);
 })
 })
 }
 }
 }
 }, 1000);

4. Restart the server, open a PDF document in two browsers, add an annotation event to one of the browser, then you will find that the event will be added synchronization to the other browser.

Technical Support

Reporting Problems

Foxit offers 24/7 support for its products and are fully supported by the PDF industry’s largest development team of support engineers. If you encounter any technical questions or bug issues when using Foxit PDF SDK for Web, please submit the problem report to the Foxit support team at http://tickets.foxitsoftware.com/create.php. In order to better help you solve the problem, please provide the following information:

  • Contact details
  • Foxit PDF SDK product and version
  • Your Operating System and IDE version
  • Detailed description of the problem
  • Any other related information, such as log file or error screenshot

Contact Information
You can contact Foxit directly, please use the contact information as follows:

Foxit Support:

  • http://www.foxitsoftware.com/support/

Sales Contact:

  • Phone: 1-866-680-3668
  • Email: sales@foxitsoftware.com

Support & General Contact:

  • Phone: 1-866-MYFOXIT or 1-866-693-6948
  • Email: support@foxitsoftware.com

Updated on July 23, 2019

Was this article helpful?

Related Articles