Skip to Content
NexPDF

Installation

Add the NexPDF web package to your app, put the WebAssembly module in place and, for the viewer, run the NexPDF WebViewer server.

English

Get the package

The source of the package is the public repository nexdevit/nexpdf-web:

git clone https://github.com/nexdevit/nexpdf-web

Add 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-web
nexpdf.js
nexpdf.d.ts
nexpdf_bg.wasm
nexpdf_lite_bg.wasm
package.json

nexpdf_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-web

The package exports these entry points:

ImportContents
@nexdevit/nexpdf-web/engineThe WebAssembly engine: loadNexPdf, PdfDocument, PageView
@nexdevit/nexpdf-web/syncNexPdfSync, the real-time collaboration client
@nexdevit/nexpdf-webThe viewer: createNexPdfViewer, NexPdfViewer
@nexdevit/nexpdf-web/reactReact and Next.js component
@nexdevit/nexpdf-web/vueVue 3 and Nuxt component
@nexdevit/nexpdf-web/angularAngular standalone component
@nexdevit/nexpdf-web/svelteSvelte 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-webviewer

It 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

On this page