Skip to Content
NexPDF

License

Activate a NexPDF web license key bound to your domain, check which modules it unlocks, and handle license errors in the browser.

English

Web keys are issued for platform web and bound to the host names of your pages. Wildcards such as *.acme.com are allowed. See Licensing for how keys are issued and bound.

Activate the engine

Call activateLicense once, after loadNexPdf() and before other calls. It accepts the license XML file's text or the bare NEX2. key:

import { loadNexPdf } from '@nexdevit/nexpdf-web/engine';

const nex = await loadNexPdf();
const xml = await (await fetch('/nexpdf_license.xml')).text();
const result = nex.activateLicense(xml, location.hostname);

console.log(result === 1 ? 'trial' : 'licensed');
ParameterValue
keyOrXmlThe license XML or the bare key
hostThe page's host name; defaults to location.hostname

It returns 2 for a commercial key and 1 for a trial key, and throws an Error with the reason when the key is rejected.

A key used in the browser is visible to anyone who opens the page. Binding it to your host names is what stops it working elsewhere.

Check the status

const status = nex.licenseStatus();
console.log(status.state, status.tier, status.days_left);

if (status.modules.includes('signatures')) {
  console.log('signing is available');
}

licenseStatus() returns the parsed JSON: state (unlicensed, trial, licensed), licensee, id, tier, modules, expires_at, days_left and watermark.

Handle errors

A rejected key throws an Error whose message gives the reason (for example an expired key, or a key for another host). The engine then stays in viewer mode:

try {
  nex.activateLicense(key, location.hostname);
} catch (e) {
  console.error('NexPDF license rejected:', (e as Error).message);
}

A call that needs a module your key does not include throws too:

try {
  doc.encrypt('user', 'owner');
} catch (e) {
  console.log((e as Error).message); // the active license does not include the 'security' module
}

Without a license, or after a rejected key, the engine stays in viewer mode: it opens, renders, extracts text and searches, and rendered pages carry the "NexPDF • Unlicensed" watermark.

Activate the viewer

The viewer runs on the NexPDF WebViewer server, so its license is activated there, not in the browser:

NEXPDF_LICENSE=/etc/nexpdf/nexpdf_license.xml nexpdf-webviewer

NEXPDF_LICENSE holds the key or the path of the XML file. Without it the server looks for nexpdf_license.xml in its working folder.

The server activates keys for platform server and the app id in NEXPDF_APP_ID (default nexpdf-webviewer), so the viewer needs a key issued for those, not a web key.

On this page