Skip to Content
NexPDF

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.

English

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

main.js
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());
OptionMeaning
fileA document to open at start: PDF, PNG, JPEG, TIFF, or a Word, Excel or PowerPoint file
passwordThe password of file, when it is an encrypted PDF
configThe UI configuration: an object, JSON text, or the path of a JSON file
licenseThe license key, or the path of the XML license file
binaryThe path of the nexpdf-webviewer engine, when it is not found on its own
menufalse keeps your own application menu instead of the File menu (Open, Save As)
windowExtra BrowserWindow options; webPreferences are merged over the secure defaults

Drive the window

openPdfWindow resolves to a PdfWindow once the reader has loaded:

MemberWhat it does
windowThe BrowserWindow, for the title, size, position and your own menus
engineThe 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' } },
  },
});
KeyWhat it does
modeConfig.initialModeThe mode the window opens in: viewer, annotations, content, pages, forms, signatures, security, redaction, measurement or ai
modeConfig.availableModesThe modes the user can switch to, in this order. With one mode the switcher is hidden
modeConfig.readOnlyViewing only: the View mode alone, without undo, redo, open, the page editor or editing rows
toolbarConfig.hiddenItemsBuilt-in items to hide, such as open, download, share, language or license (the license chip)
annotationsConfig, formsConfigThe tools, colours and stamps offered; see Annotations
readerConfiglayout, zoom and nightMode; see Viewing pages
collaboration.userNameThe name shown on comments
globalConfigthemeMode, 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.

ModeIdModule
Viewviewernone
Annotate, Measureannotations, measurementannotations
Formsformsforms
Edit, Pagescontent, pageseditor
Protectsecuritysecurity; editor for document properties, standards for the ISO standards
Redactredactionredaction
Signsignaturessignatures
Convertaiconversion for exports, ocr for OCR; comparing needs none

See the guides for what each mode does.

On this page