Skip to Content
NexPDF

License

Activate a NexPDF license key in a Flutter app, read the license status and handle license errors.

English

Activate the license once per launch, before other NexPDF calls. The key is accepted as the license XML file's text or the bare NEX2. key. Keys are bound to a platform (ios or android, and macos, windows or linux on desktop) and to the app id: the bundle id on iOS, the package name on Android. See Licensing for how keys are issued and bound.

Activate

import 'package:flutter/services.dart';
import 'package:nexpdf_flutter/nexpdf_flutter.dart';

final sdk = NexPdfFlutter();
final key = await rootBundle.loadString('assets/nexpdf_license.xml');
sdk.activateLicense(key, appId: 'com.acme.app');
ParameterValue
licenseThe license XML or the bare key
appIdThe bundle id (iOS) or package name (Android) the key was issued for
platformDefaults to NexPdfFlutter.platform: ios, android, macos, windows or linux

activateLicense returns 2 for a commercial key and 1 for a trial key. A rejected key throws NexPdfException with the engine's reason:

try {
  final status = sdk.activateLicense(key, appId: 'com.acme.app');
  debugPrint(status == 1 ? 'trial' : 'licensed');
} on NexPdfException catch (e) {
  debugPrint('NexPDF license rejected: $e');
}

The license is process-wide, so it also covers the native reader on iOS and Android.

Fixed in 1.0.1

In 1.0.0, activateLicense threw for every result other than 1, so a valid commercial key looked like a failure. Since 1.0.1 it accepts any positive result and returns it. See the changelog.

The exception carries the message only. The codes behind the messages are:

CodeMeaning
2Commercial key, active
1Trial key, active (pages keep the watermark)
-1Malformed key
-2Bad signature
-3Unsupported key version
-4Expired
-5Not yet valid (check the clock)
-6Wrong platform
-7Wrong application id

Check the status

The Dart API has no status method. Read nexpdf_license_status_json through dart:ffi:

import 'dart:convert';

Map<String, Object?> licenseStatus() {
  final status = nexpdfLib.lookupFunction<Pointer<Utf8> Function(), Pointer<Utf8> Function()>(
      'nexpdf_license_status_json');
  return jsonDecode(takeString(status()) ?? '{}') as Map<String, Object?>;
}

final s = licenseStatus();
print('${s['state']} ${s['tier']} ${s['days_left']}');

The status has state (unlicensed, trial, licensed), licensee, id, tier, modules, expires_at, days_left and watermark.

Missing modules

A call that needs a module your key does not include fails, and sdk.lastError() says why, for example the active license does not include the 'forms' module. Without a license the SDK stays in viewer mode: it opens, renders and searches, and rendered pages carry the "NexPDF • Unlicensed" watermark.

On this page