License
Activate a NexPDF license key in a .NET MAUI app, check which modules it unlocks, and handle license errors.
Activate the license once per process, before the first document opens. The key must be issued for the device's platform and for your app id (the bundle id on iOS and Mac Catalyst, the package name on Android). See Licensing for how keys are issued and bound.
NexPdfEngine.Platform gives the platform id to use on the current device:
| Device | NexPdfEngine.Platform |
|---|---|
| iOS, Mac Catalyst | ios |
| Android | android |
| Windows | windows |
Fixed in 1.0.1
In 1.0.0, NexPdfEngine.Activate(license, appId) returned true only for a trial key: a commercial
key activated correctly, but Activate treated the engine's result 2 as a failure, returned
false and set NexPdfEngine.LastError. From 1.0.1 it returns true for both. On 1.0.0, call
NexPdfSdk.ActivateLicense(key, NexPdfEngine.Platform, appId) instead, as below.
Activate
using Nexdevit.NexPdf;
using Nexdevit.NexPdf.Maui;
try
{
var result = NexPdfSdk.ActivateLicense(licenseXml, NexPdfEngine.Platform, AppInfo.PackageName);
System.Diagnostics.Debug.WriteLine(result == 1 ? "trial" : "licensed");
}
catch (NexPdfException e)
{
System.Diagnostics.Debug.WriteLine($"NexPDF license rejected ({e.Code}): {e.Message}");
}NexPdfSdk.ActivateLicense accepts the license XML or the bare NEX2. key, returns 2 for a
commercial key and 1 for a trial key, and throws NexPdfException with a negative Code when it
rejects the key.
Check the status
using System.Text.Json.Nodes;
var status = JsonNode.Parse(NexPdfSdk.LicenseStatusJson())!;
var licensed = status["state"]!.GetValue<string>() == "licensed";
if (NexPdfSdk.IsLicensed("annotations"))
System.Diagnostics.Debug.WriteLine("annotations are available");LicenseStatusJson() returns state (unlicensed, trial, licensed), licensee, id, tier,
modules, expires_at, days_left and watermark.
Error codes
| Code | Meaning |
|---|---|
| -1 | Malformed key |
| -2 | Bad signature |
| -3 | Unsupported key version |
| -4 | Expired |
| -5 | Not yet valid (check the clock) |
| -6 | Wrong platform |
| -7 | Wrong application id |
A call that needs a module your key does not include throws NexPdfException with a message that
names the module.
Without a license, or after a rejected key, the SDK stays in viewer mode: PdfView opens and shows
documents, text extraction and search work, and rendered pages carry the "NexPDF • Unlicensed"
watermark.