Skip to Content
NexPDF

Installation

Add the NexPDF Electron package to your app, put the nexpdf-webviewer engine where it is found, and package it with electron-builder.

English

Install the package

The source of the package is the public repository nexdevit/nexpdf-electron:

git clone https://github.com/nexdevit/nexpdf-electron
npm install ./nexpdf-electron

electron 28 or later must be installed in your app.

The package depends on the Node.js SDK, @nexdevit/nexpdf-node of the same version, for its document API (documents() and openDocumentFile()). Install it first, with its WebAssembly engine, as described in the Node.js installation:

npm install ./nexpdf-nodejs ./nexpdf-electron

The window and startEngine do not use it.

Get the engine

Download the engine for each platform you ship from the v1.1.0 release:

PlatformArchiveBinary
Linux x64nexpdf-webviewer-1.1.0-linux-x64.tar.gznexpdf-webviewer
Linux arm64nexpdf-webviewer-1.1.0-linux-arm64.tar.gznexpdf-webviewer
macOSnexpdf-webviewer-1.1.0-macos-universal.tar.gznexpdf-webviewer
Windows x64nexpdf-webviewer-1.1.0-windows-x64.zipnexpdf-webviewer.exe

Put the engine where it is found

The engine is looked up in this order:

  1. the binary option of openPdfWindow or startEngine;
  2. the NEXPDF_BINARY environment variable;
  3. process.resourcesPath/nexpdf/nexpdf-webviewer (.exe on Windows), for packaged apps;
  4. bin/<platform>-<arch>/ inside the package, where the folder name is process.platform and process.arch, for example darwin-arm64, linux-x64 or win32-x64;
  5. bin/ inside the package.

During development, extract the archive into the package's bin/ folder:

mkdir -p node_modules/@nexdevit/nexpdf-electron/bin/linux-x64
tar -xzf nexpdf-webviewer-1.1.0-linux-x64.tar.gz -C node_modules/@nexdevit/nexpdf-electron/bin/linux-x64

or point to it:

NEXPDF_BINARY=/opt/nexpdf/nexpdf-webviewer npx electron .

When the engine is missing, openPdfWindow throws "NexPDF engine not found" with the list of places it looked in.

Check the installation

npx electron node_modules/@nexdevit/nexpdf-electron/demo/main.js /path/to/file.pdf

The demo opens the file in a NexPDF window.

Packaging with electron-builder

Ship the engine as an extra resource in a nexpdf folder, so it is found under process.resourcesPath in the packaged app. Keep one folder per platform in your project:

nexpdf-webviewer
main.js
package.json
package.json
{
  "build": {
    "mac": { "extraResources": [{ "from": "bin/mac", "to": "nexpdf" }] },
    "linux": { "extraResources": [{ "from": "bin/linux", "to": "nexpdf" }] },
    "win": { "extraResources": [{ "from": "bin/win", "to": "nexpdf" }] }
  }
}

On macOS and Linux, keep the executable bit on the binary.

Building the engine yourself

With access to the NexPDF source tree, cargo build --release -p nexpdf-webviewer builds the engine into target/release/, which the package also searches when it runs from the source tree.

On this page