For the complete documentation index, see llms.txt. This page is also available as Markdown.

Build an Electron PDF viewer with Apryse WebViewer SDK

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.

Prerequisites

This guide assumes basic familiarity with Electron development. Before you start:

spinner

1. Create an Electron project

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.

  1. In your terminal, go to the directory where you want to create the project.

  2. Create a new project directory, initialize your project, and generate a package.json file:

mkdir webviewer-electron
cd webviewer-electron
npm init -y
  1. Update the main entry point in the package.json file to main.js :

  1. Update the scripts section and the start command in the package.json:

The final package.json should look like this:

  1. In your project directory, install Electron:

2. Install WebViewer

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:

3. Copy WebViewer assets

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. From your project root, create the public/lib/webviewer directory if it doesn't already exist:

  1. Copy all WebViewer static assets from node_modules/@pdftron/webviewer/public into the new public/lib/webviewer directory:

  1. Copy the webviewer.min.js library file from node_modules to the public directory:

Info

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:

Info

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.

4. Create the PDF viewer

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.

  1. Open Visual Studio Code.

  2. Create an index.html file in your project root and add the following to define your app UI:

  1. 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:

  1. Create a render.js file in your project root, then add the following code to initialize WebViewer inside the HTML UI:

Info

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.

  1. Save all files modified in this section.

5. Verify your output

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:

  1. The Electron app opens and displays the WebViewer UI with the PDF loaded.

Get started video

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.

Next steps

Check out the resources below.

UsageGuidesSamplesAPI docs

Last updated

Was this helpful?