Skip to Content
NexPDF

License

Activate a NexPDF license key in PHP, check which modules it unlocks, and handle license errors.

English

Call NexPdf::activateLicense once per process, 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.

Under PHP-FPM, call it from your bootstrap code so that every worker process has activated the key before it uses NexPDF.

Activate

use Nexdevit\NexPdf\NexPdf;

$result = NexPdf::activateLicense(file_get_contents('nexpdf_license.xml'), 'server', 'com.acme.invoicing');
echo $result === 1 ? 'trial' : 'licensed', "\n";
ParameterValue
$keyOrXmlThe license XML or the bare key
$platformserver (default), linux, macos or windows: one of the platforms on the key
$appIdThe application id the key was issued for

It returns 2 for a commercial key and 1 for a trial key. NexPdf::PLATFORMS lists every platform name a key can be bound to.

Reading the key from the environment

On servers, keep the key out of the image and read it from a secret:

NexPdf::activateLicense(getenv('NEXPDF_LICENSE_KEY'), 'server', getenv('NEXPDF_APP_ID') ?: 'com.acme.invoicing');

Check the status

$status = NexPdf::licenseStatus();
echo $status['state'], ' ', $status['tier'] ?? '', ' ', $status['days_left'] ?? '', "\n";

if (NexPdf::isLicensed('signatures')) {
    echo "signing is available\n";
}

licenseStatus() returns the decoded JSON as an array: state (unlicensed, trial, licensed), licensee, id, tier, modules, expires_at, days_left and watermark. Without a license only state, modules (['viewer']) and watermark are present. NexPdf::licenseStatusJson() returns the JSON string.

Handle errors

A rejected key throws Nexdevit\NexPdf\NexPdfException with the negative code as the exception code:

use Nexdevit\NexPdf\NexPdfException;

try {
    NexPdf::activateLicense($key, 'server', 'com.acme.invoicing');
} catch (NexPdfException $e) {
    match ($e->getCode()) {
        -4 => error_log('NexPDF license expired: renew it in the dashboard'),
        -6, -7 => error_log('NexPDF license is for another platform or app id: ' . $e->getMessage()),
        default => error_log(sprintf('NexPDF license rejected (%d): %s', $e->getCode(), $e->getMessage())),
    };
}

A call that needs a module your key does not include throws NexPdfException with code 0:

try {
    $doc->encryptAes256('user', 'owner');
} catch (NexPdfException $e) {
    echo $e->getMessage();  // the active license does not include the 'security' module
}
CodeMeaning
-1Malformed key
-2Bad signature
-3Unsupported key version
-4Expired
-5Not yet valid (check the clock)
-6Wrong platform
-7Wrong application id

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.

On this page