License
Activate a NexPDF license key in a React Native app for its iOS bundle id and Android package name, check which modules it unlocks, and handle license errors.
Call NexPdf.activateLicense once per app launch, before other NexPDF calls. It accepts the license
XML file's text or the bare NEX2. key. See Licensing for how keys are
issued and bound.
Activate
import { NexPdf } from '@nexdevit/nexpdf-react-native';
const result = await NexPdf.activateLicense(LICENSE_XML, 'com.acme.reader');
console.log(result === 1 ? 'trial' : 'licensed');| Parameter | Value |
|---|---|
keyOrXml | The license XML or the bare key |
appId | The app id the key was issued for: the bundle id on iOS, the package name on Android |
The platform is picked from Platform.OS: ios or android. A key for both platforms works
on both; pass the app id for each one if they differ:
import { Platform } from 'react-native';
await NexPdf.activateLicense(LICENSE_XML, Platform.OS === 'ios' ? 'com.acme.reader' : 'com.acme.reader.android');It resolves to 2 for a commercial key and 1 for a trial key.
Check the status
const status = await NexPdf.licenseStatus();
console.log(status.state, status.tier, status.days_left);
if (status.modules.includes('signatures')) {
console.log('signing is available');
}licenseStatus() resolves to the parsed JSON: state (unlicensed, trial, licensed),
licensee, id, tier, modules, expires_at, days_left and watermark.
Handle errors
A rejected key rejects the promise with NexPdfError, whose message gives the reason (for example
an expired key, or a key for another platform or app id):
import { NexPdf, NexPdfError } from '@nexdevit/nexpdf-react-native';
try {
await NexPdf.activateLicense(LICENSE_XML, 'com.acme.reader');
} catch (e) {
if (e instanceof NexPdfError) console.warn('NexPDF license rejected:', e.message);
}A call that needs a module your key does not include rejects too. error.license is true when the
message is about the license, so you can tell these failures from others:
try {
await doc.encryptAes256('user', 'owner');
} catch (e) {
if (e instanceof NexPdfError && e.license) {
showUpgradeMessage(); // the active license does not include the 'security' module
} else {
throw e;
}
}Without a license, or after a rejected key, the SDK stays in viewer mode: it opens, renders, extracts text and searches, and rendered pages carry the "NexPDF • Unlicensed" watermark.