Integrate WebViewer JavaScript PDF Viewer & Editor into an Electron Desktop App

This guide will show you how to integrate WebViewer Document Viewer & Editor into an Electron desktop application.

You can watch a step-by-step video to help you get started.

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

Prerequisites

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

  • Download and install Electron.
  • Platform specific prerequisites. Electron applications can be built for several platforms and each has its own prerequisites. Please ensure they are fulfilled for your required platform by referring to the electron.js documentation.
  • Get your Apryse trial key.

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-electron-sample repository:

sh

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

Enter the directory and run npm install:

sh

1cd webviewer-electron-sample
2npm install

This will automatically download and extract the Apryse WebViewer Package.

2. Run the Sample

To run the sample, make sure you are in the webviewer-electron-sample directory and execute

sh

1npm start

You should see the application start up. It will load the WebViewer and display the PDF sample in /public/files:

Apryse Docs Image

If you run into issues with installing and/or running the application, please return and ensure you have the prerequisites installed.

3. Usage

To call more WebViewer APIs, open /src/App.js in your favorite text editor and add the API calls to the callback for the WebViewer instantiation. Add your own license key in place of 'YOUR_LICENSE_KEY'.:

1WebViewer({
2 licenseKey: 'YOUR_LICENSE_KEY', // sign up to get a key at https://dev.apryse.com
3}, wvElement
4 .then(instance => {
5 const { Core, UI } = instance;
6 const { documentViewer, annotationManager, Annotations, Tools } = instance.Core;
7
8 // See https://docs.apryse.com/web/guides/ for more info.
9 documentViewer.addEventListener('documentLoaded', function() {
10 // call methods relating to the loaded document
11 });
12});

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:

Apryse Docs Image

Troubleshooting

Network Failure More information about fixing the Network Failure issue on WebViewer.

Next step

You can find the full source code for this project here.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales