Skip to Content
NexPDF

License

Activate a NexPDF license key in Java, 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.

Activate

import com.nexdevit.nexpdf.NexPdf;
import java.nio.file.Files;
import java.nio.file.Path;

int result = NexPdf.activateLicense(Files.readString(Path.of("nexpdf_license.xml")), "server", "com.acme.invoicing");
System.out.println(result == 1 ? "trial" : "licensed");
ParameterValue
keyOrXmlThe license XML or the bare key
platformserver, 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.

Reading the key from the environment

NexPdf.activateLicense(System.getenv("NEXPDF_LICENSE_KEY"), "server",
        System.getenv().getOrDefault("NEXPDF_APP_ID", "com.acme.invoicing"));

Check the status

String status = NexPdf.licenseStatusJson();   // parse with any JSON library
System.out.println(status);

if (NexPdf.isLicensed("signatures")) {
    System.out.println("signing is available");
}

licenseStatusJson() returns state (unlicensed, trial, licensed), licensee, id, tier, modules, expires_at, days_left and watermark.

Handle errors

A rejected key throws NexPdfException (unchecked) with the negative code in code():

try {
    NexPdf.activateLicense(key, "server", "com.acme.invoicing");
} catch (NexPdfException e) {
    switch (e.code()) {
        case -4 -> log.error("NexPDF license expired: renew it in the dashboard");
        case -6, -7 -> log.error("NexPDF license is for another platform or app id: {}", e.getMessage());
        default -> log.error("NexPDF license rejected ({}): {}", e.code(), e.getMessage());
    }
}

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

try {
    doc.encryptAes256("user", "owner");
} catch (NexPdfException e) {
    System.out.println(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