Platform notes
Processes and threads, memory, packaging, code signing and network access of NexPDF for Electron, which runs the native engine as a helper process.
Processes
A NexPDF window involves three processes:
| Process | What runs there |
|---|---|
| Your Electron main process | @nexdevit/nexpdf-electron: it starts the engine, opens the window and talks to the engine over HTTP on 127.0.0.1 |
The engine, nexpdf-webviewer | The native NexPDF engine and the reader's server, one process per openPdfWindow or startEngine call |
| The window's renderer | The reader UI, loaded from the engine, with contextIsolation, sandbox and no Node integration |
- Rendering, OCR, conversion and signing run in the engine process, not in your main process. The SDK's calls only send requests and wait for replies, so they do not block the main process or the window while the engine works.
- Each engine holds one current document.
openDocumentandpdf.openreplace it. To show several documents at once, open several windows; each gets its own engine. openPdfWindowstops its engine when the window closes or the app quits. An engine fromstartEngineruns until you callengine.close(); call it when your batch is done and onapp.on('will-quit').- The license is per engine: pass
licenseto everyopenPdfWindowandstartEnginecall.
Memory
- The engine reads each document fully into memory. Budget roughly the file size plus the decoded pages the user looks at.
- The engine's renderer keeps caches of parsed fonts, glyphs and decoded images, bounded by size and dropping the least recently used entries first; together they can hold up to about 1.3 GB in an engine that renders many large, image-heavy files. Memory that stays high while a window is open is this cache being reused, not a leak.
- Every window has its own engine and its own caches, so memory grows with the number of open windows. Closing a window ends its engine and returns all of its memory to the system.
- The engine is not part of Electron's process list in
app.getAppMetrics();engine.process.pidgives its process id if you monitor it.
Packaging and size
- The engine is one native executable per platform: Linux x64 and arm64, macOS (universal, both architectures in one file) and Windows x64. Ship the ones for the platforms you build.
- It includes the Liberation fonts used for non-embedded standard fonts and PDF/A, so it needs no font files.
- Ship it outside the
asararchive, for example with electron-builder'sextraResourcesinto anexpdffolder, whereprocess.resourcesPath/nexpdf/finds it. An executable insideasarcannot be started. See Installation. - Keep the executable bit on macOS and Linux.
- When you sign and notarise a macOS app, sign the engine executable too, like any other helper binary you ship in the app bundle.
- The Linux release binaries are built on Ubuntu 22.04 and need glibc 2.35 or later.
Temporary files
When config or uiConfig is an object or JSON text, the SDK writes it to a private temporary
file (mode 0600) that the engine reads, and removes it when the engine exits. A string that is not
JSON is taken as the path of a JSON file and left alone.
Network
- The engine listens on
127.0.0.1only, on a random free port, and the window cannot navigate to other origins. It is not reachable from other machines. Like any loopback service, it can be reached by other programs running on the same computer while it runs. - The engine makes no network calls of its own: license keys are verified offline and documents stay
on the machine. The exceptions are the ones the user or you turn on:
- signing with a trusted timestamp (TSA URL) or with revocation data for long-term validation contacts the TSA and the OCSP and CRL servers named in the certificates;
- when
ANTHROPIC_API_KEYis in the engine's environment, the assistant sends the passages it retrieved from the document to the Anthropic API to write its answer. Without the key, the assistant works offline.
- Links in documents that point to other sites open in the user's browser, not in the window.
Programmatic work
documents() and openDocumentFile() (1.1 and later) give the main process a document API: the
Node.js SDK, whose engine is NexPDF compiled to WebAssembly and runs inside your
process, not in the helper. See
Opening and saving.
- Its calls are synchronous (only the ones that read or write files, such as
openandsave, return promises) and run on the thread that makes them. A long call, such as OCR or converting a large file, blocks the main process and with it every window's events; run heavy work in aworker_threadsworker or autilityProcess. - The engine is loaded once per process. Documents hold WebAssembly memory until
doc.close();doc.trimMemory()compacts a long-lived document anddoc.memoryUsage()estimates its size. - Its engine makes no network calls itself (
sign,addLtvandtsa_urlwork at B-B only). The online calls (doc.signOnline,completeExternalSignatureOnline,timestampSignature,addLtvOnline,timestampDocument,upgradeSignature) fetch time-stamps and OCSP and CRL data with the main process'sfetch, for B-T, B-LT and B-LTA; renderers reach them throughhandleSigning. See Long-term signatures. - Every function of the WebAssembly engine is in
documents(), among themocrLoadModelfor neural OCR models. - It has the limits described in the Node.js platform notes.