Skip to Content
NexPDF

License

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

English

Call NexPdfSdk.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

using Nexdevit.NexPdf;

var result = NexPdfSdk.ActivateLicense(File.ReadAllText("nexpdf_license.xml"), "server", "com.acme.invoicing");
Console.WriteLine(result == 1 ? "trial" : "licensed");
ParameterValue
keyOrXmlThe license XML or the bare key
platformserver, linux, macos or windows: one of the platforms on the key (NexPdfSdk.Platforms lists them all)
appIdThe application id the key was issued for

It returns 2 for a commercial key and 1 for a trial key.

ASP.NET Core

Activate before the first request, for example in Program.cs:

Program.cs
var builder = WebApplication.CreateBuilder(args);
NexPdfSdk.ActivateLicense(builder.Configuration["NexPdf:LicenseKey"]!, "server", "com.acme.invoicing");

Check the status

using System.Text.Json.Nodes;

var status = JsonNode.Parse(NexPdfSdk.LicenseStatusJson())!;
Console.WriteLine($"{status["state"]} {status["tier"]} {status["modules"]}");

if (NexPdfSdk.IsLicensed("signatures"))
    Console.WriteLine("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 with the negative code in Code:

try
{
    NexPdfSdk.ActivateLicense(key, "server", "com.acme.invoicing");
}
catch (NexPdfException e) when (e.Code == -4)
{
    logger.LogError("NexPDF license expired: renew it in the dashboard");
}
catch (NexPdfException e) when (e.Code is -6 or -7)
{
    logger.LogError("NexPDF license is for another platform or app id: {Message}", e.Message);
}
catch (NexPdfException e)
{
    logger.LogError("NexPDF license rejected ({Code}): {Message}", e.Code, e.Message);
}

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

try
{
    doc.EncryptAes256("user", "owner");
}
catch (NexPdfException e)
{
    Console.WriteLine(e.Message);  // 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