Installation
Add the NexPDF web package to your app, put the WebAssembly module in place and, for the viewer, run the NexPDF WebViewer server.
Get the package
The source of the package is the public repository nexdevit/nexpdf-web:
git clone https://github.com/nexdevit/nexpdf-webAdd the WebAssembly module
The WebAssembly engine is distributed separately. Download nexpdf-wasm-web-1.1.0.tar.gz from the
v1.1.0 release and extract it into
the package. It creates the wasm/ folder:
tar -xzf nexpdf-wasm-web-1.1.0.tar.gz -C nexpdf-webnexpdf_bg.wasm has the Liberation fonts compiled in. nexpdf_lite_bg.wasm is about 4 MB
smaller and fetches the fonts at run time; see Lighter module.
Install it in your app
npm install ./nexpdf-webThe package exports these entry points:
| Import | Contents |
|---|---|
@nexdevit/nexpdf-web/engine | The WebAssembly engine: loadNexPdf, PdfDocument, PageView |
@nexdevit/nexpdf-web/sync | NexPdfSync, the real-time collaboration client |
@nexdevit/nexpdf-web | The viewer: createNexPdfViewer, NexPdfViewer |
@nexdevit/nexpdf-web/react | React and Next.js component |
@nexdevit/nexpdf-web/vue | Vue 3 and Nuxt component |
@nexdevit/nexpdf-web/angular | Angular standalone component |
@nexdevit/nexpdf-web/svelte | Svelte 4/5 and SvelteKit component |
Serve the module
loadNexPdf() fetches nexpdf_bg.wasm next to the JavaScript module, which bundlers such as Vite
resolve on their own. When your setup serves the file from somewhere else, copy it to your static
folder and pass its URL:
import { loadNexPdf } from '@nexdevit/nexpdf-web/engine';
const nex = await loadNexPdf('/assets/nexpdf_bg.wasm');
console.log(nex.version());Lighter module
Load nexpdf_lite_bg.wasm by URL and register the fonts before you open documents that use
non-embedded standard fonts (Helvetica, Times, Courier) or convert to PDF/A:
const nex = await loadNexPdf('/assets/nexpdf_lite_bg.wasm');
if (!nex.hasBundledFonts()) {
await nex.loadStandardFonts('/fonts/'); // resolves to the number of fonts registered
}loadStandardFonts(baseUrl) fetches twelve files from baseUrl: LiberationSans-,
LiberationSerif- and LiberationMono- with Regular, Bold, Italic and BoldItalic, plus
.ttf (for example LiberationSans-BoldItalic.ttf). It does nothing when the fonts are compiled
in. To register one font yourself, call nex.registerStandardFont(bytes): the PostScript name of
the TrueType font picks the standard font it replaces.
The lighter module is also built without the neural OCR engine (the neural feature); OCR uses the
built-in engine in both modules.
The WebViewer server (viewer only)
The viewer components need the NexPDF WebViewer server. The nexpdf-webviewer binary is attached to
the NexPDF Electron release as
nexpdf-webviewer-1.1.0-<platform> (linux-x64, linux-arm64, macos-universal,
windows-x64). Start it with your page's origin allowed to frame it:
NEXPDF_FRAME_ANCESTORS="https://app.example.com" ./nexpdf-webviewerIt listens on http://127.0.0.1:7878 by default (NEXPDF_ADDR changes it). See
Viewer.
Building the module yourself
With access to the NexPDF source tree and wasm-pack, run from sdks/web:
npm run build:wasm # wasm/nexpdf.js and wasm/nexpdf_bg.wasm, fonts compiled in
npm run build:wasm:lite # wasm/nexpdf_lite_bg.wasm, no bundled fonts