Viewer
Open the NexPDF reader in an Electron window, choose its window, menu and engine options, drive it from the main process, and customise it with the shared UI configuration.
The Electron SDK is the NexPDF reader and editor in a window. openPdfWindow starts the engine and
opens a BrowserWindow on it; the UI is the same as the web viewer, and the
same UI configuration customises it. This page covers what the SDK exposes; every option and type is
in the API reference.
Open a window
const { app } = require('electron');
const { openPdfWindow } = require('@nexdevit/nexpdf-electron');
app.whenReady().then(async () => {
const pdf = await openPdfWindow({
file: '/path/to/contract.pdf',
license: '/path/to/nexpdf_license.xml',
config: {
modeConfig: { initialMode: 'annotations', availableModes: ['viewer', 'annotations', 'forms'] },
globalConfig: { language: 'pt', accentColor: '#0F766E' },
},
window: { width: 1440, height: 900, title: 'Acme Docs' },
});
});
app.on('window-all-closed', () => app.quit());| Option | Meaning |
|---|---|
file | A document to open at start: PDF, PNG, JPEG, TIFF, or a Word, Excel or PowerPoint file |
password | The password of file, when it is an encrypted PDF |
config | The UI configuration: an object, JSON text, or the path of a JSON file |
license | The license key, or the path of the XML license file |
binary | The path of the nexpdf-webviewer engine, when it is not found on its own |
menu | false keeps your own application menu instead of the File menu (Open, Save As) |
window | Extra BrowserWindow options; webPreferences are merged over the secure defaults |
Drive the window
openPdfWindow resolves to a PdfWindow once the reader has loaded:
| Member | What it does |
|---|---|
window | The BrowserWindow, for the title, size, position and your own menus |
engine | The engine behind the window: url, port, process and close() |
open(file, { password }) | Opens another file in the window, in place of the current one, and reloads it |
save(file) | Writes the current document, with every edit, to file |
bytes() | The current document, with every edit, as a Buffer |
const { dialog } = require('electron');
const pdf = await openPdfWindow({ file, license, menu: false });
pdf.window.setTitle('Contract 42');
const { filePath } = await dialog.showSaveDialog(pdf.window, { defaultPath: 'contract-42.pdf' });
if (filePath) await pdf.save(filePath);The SDK has no other commands or events: the reader does not tell the main process about page changes, mode changes or edits, and custom toolbar items are shown but their taps are not reported to the main process. Use your own menus for app actions.
Use your own window
startEngine starts an engine without a window. Load its url in a window you create, with the
same secure web preferences:
const { BrowserWindow } = require('electron');
const { startEngine } = require('@nexdevit/nexpdf-electron');
const engine = await startEngine({ license, uiConfig: { modeConfig: { readOnly: true } }, file });
const win = new BrowserWindow({ webPreferences: { contextIsolation: true, sandbox: true, nodeIntegration: false } });
win.on('closed', () => engine.close());
await win.loadURL(engine.url);You then handle navigation, downloads and menus yourself; openPdfWindow does it for you.
UI configuration
One JSON document customises the reader: modes, hidden items, tools, theme, accent colour and
language. Pass it as config (openPdfWindow) or uiConfig (startEngine). Every key is
optional, and unknown keys and ids are ignored.
await openPdfWindow({
file,
license,
config: {
modeConfig: { initialMode: 'viewer', availableModes: ['viewer', 'annotations', 'signatures'] },
toolbarConfig: { hiddenItems: ['share', 'language', 'license'] },
annotationsConfig: { availableTools: ['ink', 'highlight', 'note'], stamps: ['APPROVED', 'REVIEWED'] },
readerConfig: { layout: 'continuous', zoom: 'fit-width' },
collaboration: { userName: 'Ana Silva' },
globalConfig: { themeMode: 'system', brand: { title: 'Acme Docs' } },
},
});| Key | What it does |
|---|---|
modeConfig.initialMode | The mode the window opens in: viewer, annotations, content, pages, forms, signatures, security, redaction, measurement or ai |
modeConfig.availableModes | The modes the user can switch to, in this order. With one mode the switcher is hidden |
modeConfig.readOnly | Viewing only: the View mode alone, without undo, redo, open, the page editor or editing rows |
toolbarConfig.hiddenItems | Built-in items to hide, such as open, download, share, language or license (the license chip) |
annotationsConfig, formsConfig | The tools, colours and stamps offered; see Annotations |
readerConfig | layout, zoom and nightMode; see Viewing pages |
collaboration.userName | The name shown on comments |
globalConfig | themeMode, accentColor, language, strings, languages, brand, cssVariables, customCss |
The web viewer lists every key and id. The same file works for both.
1.0.1
In 1.0.0, only a file path worked as config or uiConfig; an object or JSON text was ignored.
Update to 1.0.1, or pass the path of a JSON file.
Modes and license modules
Each mode needs the license module of its feature; offer only the modes your key includes.
| Mode | Id | Module |
|---|---|---|
| View | viewer | none |
| Annotate, Measure | annotations, measurement | annotations |
| Forms | forms | forms |
| Edit, Pages | content, pages | editor |
| Protect | security | security; editor for document properties, standards for the ISO standards |
| Redact | redaction | redaction |
| Sign | signatures | signatures |
| Convert | ai | conversion for exports, ocr for OCR; comparing needs none |
See the guides for what each mode does.