Integrate WebViewer JavaScript PDF Viewer & Editor into a Cordova App

This guide will show you how to integrate WebViewer Document Viewer & Editor into a Cordova application.

You can also download a ready-to-go sample on GitHub.

Prerequisites

Prior to starting, you should have already installed Node and npm.

License Key

Apryse collects some data regarding your usage of the SDK for product improvement.

If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.

Get Started with the Sample

1. Clone the Sample

Clone the webviewer-cordova-sample repository:

sh

1git clone https://github.com/ApryseSDK/webviewer-cordova-sample.git

Enter the directory and run npm install:

sh

1cd webviewer-cordova-sample
2npm install

This will automatically download and extract the Apryse WebViewer Package.

2. Run the sample

Run the application by executing:

sh

1npm start

If your build fails, use the following command to see a list of requirements for your added platforms:

sh

1cordova requirements

3. Usage

To call more WebViewer APIs, open /www/js/index.js in your favorite text editor and add the API calls to the callback for the WebViewer instantiation:

1WebViewer({
2 path: "js/lib",
3 licenseKey: 'YOUR_LICENSE_KEY', // sign up to get a key at https://dev.apryse.com
4 webviewerServerURL: 'https://demo.apryse.com/', // Make sure to change this option to point to your own server in production
5 initialDoc: 'https://pdftron.s3.amazonaws.com/downloads/pl/sample.pdf',
6 enableAnnotations: true,
7 disabledElements: [
8 'menuButton'
9 ]
10}, document.getElementById('viewer'))
11 .then(function(instance) {
12 const { documentViewer, annotationManager, Annotations, Tools } = instance.Core;
13
14 // See https://docs.apryse.com/web/guides/ for more info.
15 documentViewer.addEventListener('documentLoaded', function() {
16 // call methods relating to the loaded document
17 });
18 });

For example, if you want to change the theme of the WebViewer to dark mode, you would add the following:

1instance.UI.setTheme('dark');

Execute npm start again and the theme of the viewer will change.

Next step

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales