Skip to Content
NexPDF

Viewing pages

Show PDF pages in an Electron window with NexPDF, and set the page layout, zoom, night reading and the panels the user sees.

English

License module

Viewing is part of the viewer module and works without a key. Unlicensed and trial pages carry a watermark; commercial keys show pages without one.

The window opens in the View mode (viewer), with the page navigation, zoom, the page layout, page rotation, night reading and full screen. The side panel shows the page thumbnails, search, the outline, comments, layers, attachments and the assistant.

Set the layout and zoom

The window takes the shared UI configuration as the config option. Write it to a JSON file and pass the path:

main.js
const { app } = require('electron');
const fs = require('node:fs');
const path = require('node:path');
const { openPdfWindow } = require('@nexdevit/nexpdf-electron');

app.whenReady().then(async () => {
  const config = path.join(app.getPath('userData'), 'nexpdf-ui.json');
  fs.writeFileSync(config, JSON.stringify({
    modeConfig: { initialMode: 'viewer', readOnly: true },
    readerConfig: { layout: 'continuous', zoom: 'fit-width', nightMode: false },
    globalConfig: { themeMode: 'system' },
  }));
  await openPdfWindow({ file: process.argv[2], config });
});
KeyValues
readerConfig.layoutsingle, continuous or double
readerConfig.zoomfit-width, fit-page or a factor such as "1.25"
readerConfig.nightModetrue shows pages with inverted colours
modeConfig.readOnlytrue allows the View mode alone and hides undo, redo, open, the page editor and every editing row

Since 1.0.1, config can also be an object or JSON text; see Viewer. In 1.0.0 only the path of a JSON file was applied.

Hide items

toolbarConfig.hiddenItems hides built-in items, for example a viewer without the Open button, download or the language picker:

{ "toolbarConfig": { "hiddenItems": ["open", "download", "share", "language", "menu.open"] } }

The toolbar ids are brand, modeSwitcher, undo, redo, search, pages, more, open, download, share, theme, language, zoom, layout, rotate, navPanel, pageNav, inspector and license. More menu rows are menu.<id>; the web viewer lists them.

Page images from code

To render pages to PNG in code, without a window, use the document API (openDocumentFile, then doc.render(page, { dpi }); see the Node.js SDK).

On this page