Skip to Content
NexPDF

License

Activate a NexPDF license key in an iOS or macOS app, check which modules it unlocks, and handle license errors.

English

Call NexPdf.activateLicense once per launch, before other NexPDF calls, for example in your App initializer or application(_:didFinishLaunchingWithOptions:). 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

let url = Bundle.main.url(forResource: "nexpdf_license", withExtension: "xml")!
let xml = try String(contentsOf: url, encoding: .utf8)
let result = try NexPdf.activateLicense(xml)
print(result == 1 ? "trial" : "licensed")
ParameterValue
keyOrXmlThe license XML or the bare key
appIdThe application id the key was issued for. Defaults to Bundle.main.bundleIdentifier
platformios or macos. Defaults to ios on iOS and macos on macOS

It returns 2 for a commercial key and 1 for a trial key, and throws NexPdfError for anything else. iOS keys are bound to the platform ios and the app's bundle id, so a key issued for com.acme.app does not work in another app.

Check the status

let status = NexPdf.licenseStatus
print(status["state"] ?? "", status["tier"] ?? "", status["days_left"] ?? "")

if NexPdf.isLicensed("signatures") {
    print("signing is available")
}

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

Handle errors

A rejected key throws NexPdfError whose message gives the engine's reason. The Swift API does not expose the numeric code; the reasons are:

do {
    _ = try NexPdf.activateLicense(key)
} catch let error as NexPdfError {
    print("NexPDF license rejected:", error.message)
}
Engine codeReason
-1Malformed key
-2Bad signature
-3Unsupported key version
-4Expired
-5Not yet valid (check the clock)
-6Wrong platform
-7Wrong application id

A call that needs a module your key does not include throws NexPdfError with isLicense set:

do {
    _ = try doc.encryptAes256(userPw: "user", ownerPw: "owner")
} catch let error as NexPdfError where error.isLicense {
    print(error.message)   // the active license does not include the 'security' module
}

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