This guide shows how to build an Electron PDF viewer using the Apryse WebViewer SDK. You'll learn how to integrate the SDK into an Electron application to render, view, and interact with PDF documents using the WebViewer UI.
You can also download a ready-to-use GitHub sample to get started quickly, or explore the interactive Showcase demo to see WebViewer's full capabilities in action.
This guide assumes basic familiarity with Electron development. Before you start:
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.
In this section, you’ll create a new Electron application using npm. This project provides the foundation for integrating Apryse WebViewer. If you already have an Electron app, skip this and continue to Install WebViewer.
package.json file:3. Update the main entry point in the package.json file to main.js :
4. Update the scripts section and the start command in the package.json:
The final package.json should look like this:
package.json
5. In your project directory, install Electron:
Next, install the Apryse WebViewer SDK using npm. This command adds the WebViewer package to your project, allowing you to integrate the PDF viewer and editor into your Electron application.
After navigating to your webviewer-electron project directory, run the following command to install WebViewer:
WebViewer needs access to its static assets at runtime, including WebAssembly modules, HTML, and CSS files. In an Electron project, you must copy these assets into the public directory so they can be served correctly. For more, see Copying WebViewer static assets.
1. In your terminal, create the public/lib/webviewer directory if it doesn't already exist:
2. Copy all WebViewer static assets from node_modules/@pdftron/webviewer/public into the new public/lib/webviewer directory:
3. Copy the webviewer.min.js library file from node_modules to the public directory:
Unlike frameworks such as Vite, Nuxt, or Next.js, Electron doesn't use a module bundler by default to resolve dependencies and prepare them for the browser. As a result, you must manually include the webviewer.min.js file in your HTML before using it.
Your project should now include a similar structure:
The path option used when initializing WebViewer must point to this directory (for example, /lib/webviewer). If the path is incorrect, WebViewer will fail to load.
In this section, you’ll add WebViewer to your Electron app by creating an HTML interface and initializing the viewer. This mounts the WebViewer UI and loads a document in your application.
index.html file in your project root and add the following to define your app UI:index.html
3. Create a main.js file in your project root, then add the following code to open an Electron window and load your index.html file:
main.js
4. Create a render.js file in your project root, then add the following code to initialize WebViewer inside the HTML UI:
render.js
5. Save all files modified in this section.
You can now load and display a PDF document in the WebViewer UI. Run your Electron application to launch WebViewer and view the PDF inside the app window.
1. From your project directory, run the following command to start the application:
A successful output looks similar to:
2. The Electron app opens and displays the WebViewer UI with the PDF loaded.
In this 5-minute video, learn how to install and integrate the Apryse WebViewer SDK into an Electron project.
Integrate the WebViewer SDK in an Electron application.
Check out the resources below.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales