Installation
Add the NexPDF Electron package to your app, put the nexpdf-webviewer engine where it is found, and package it with electron-builder.
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-electronelectron 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-electronThe window and startEngine do not use it.
Get the engine
Download the engine for each platform you ship from the v1.1.0 release:
| Platform | Archive | Binary |
|---|---|---|
| Linux x64 | nexpdf-webviewer-1.1.0-linux-x64.tar.gz | nexpdf-webviewer |
| Linux arm64 | nexpdf-webviewer-1.1.0-linux-arm64.tar.gz | nexpdf-webviewer |
| macOS | nexpdf-webviewer-1.1.0-macos-universal.tar.gz | nexpdf-webviewer |
| Windows x64 | nexpdf-webviewer-1.1.0-windows-x64.zip | nexpdf-webviewer.exe |
Put the engine where it is found
The engine is looked up in this order:
- the
binaryoption ofopenPdfWindoworstartEngine; - the
NEXPDF_BINARYenvironment variable; process.resourcesPath/nexpdf/nexpdf-webviewer(.exeon Windows), for packaged apps;bin/<platform>-<arch>/inside the package, where the folder name isprocess.platformandprocess.arch, for exampledarwin-arm64,linux-x64orwin32-x64;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-x64or 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.pdfThe 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:
{
"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.