Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
Toggle table of contents sidebar

# License handling

## Activating a license

One of the following methods can be used to activate a license programmatically:

- DocumentLicense.activate Method

- DocumentLicense.activateBuffer Method

- DocumentLicense.activateActivationKey Method

- DocumentLicense.activateActivationKeyBuffer Method

- DocumentLicense.activateSerialKey Method

- DocumentLicense.activateSerialKeyBuffer Method

Here is an example how to activate a license using a serial number:

Python

    hardware_code = id3document.DocumentLicense.get_host_hardware_code(id3document.LicenseHardwareCodeType.WINDOWS_OS)
    print(f"Hardware code   : {hardware_code}")

    try:
        id3document.DocumentLicense.activate_serial_key(hardware_code, license_key, hostname, license_path)
        print("License activated successfully")
    except id3document.DocumentException as ex:
        print(f"License activation failed: {ex}")

Dart

    String hardwareCode = DocumentLicense.getHostHardwareCode(LicenseHardwareCodeType.android);

    try {
      DocumentLicense.activateSerialKey(hardwareCode, "XXXX-XXXX-XXXX-XXXX", "[Computer name]", "id3Document.lic");
    } catch (DocumentException ex) {
      print(ex.message);
    }

C#

    string hardwareCode = DocumentLicense.GetHostHardwareCode(LicenseHardwareCodeType.WindowsOs);

    try
    {
        DocumentLicense.ActivateSerialKey(hardwareCode, "XXXX-XXXX-XXXX-XXXX", "[Computer name]", "id3Document.lic");
    }
    catch (DocumentException ex)
    {
        Console.WriteLine(ex.Message);
    }

Java

    String hardwareCode = DocumentLicense.getHostHardwareCode(LicenseHardwareCodeType.LINUX_OS);

    try {
        DocumentLicense.activateSerialKey(hardwareCode, "XXXX-XXXX-XXXX-XXXX", "[Computer name]", "id3Document.lic");
    } catch (DocumentException ex) {
        System.out.println(ex.getMessage());
    }

Kotlin

    val hardwareCode = DocumentLicense.getHostHardwareCode(LicenseHardwareCodeType.ANDROID)

    try {
        DocumentLicense.activateSerialKey(hardwareCode, "XXXX-XXXX-XXXX-XXXX", "[Computer name]", "id3Document.lic")
    } catch (ex: DocumentException) {
        println(ex.message)
    }

C

    int err;
    char hwCode[256];
    int hwCodeSize = 256;

    err = id3DocumentLicense_GetHostHardwareCode(id3DocumentLicenseHardwareCodeType_WindowsOs, hwCode, &hwCodeSize, NULL);

    if (err == id3DocumentError_Success)
    {
        int licenseBufferSize = 1024*1024;
        unsigned char *licenseBuffer = (unsigned char*)malloc(size);

        err = id3DocumentLicense_ActivateSerialKeyBuffer(hwCode, "XXXX-XXXX-XXXX-XXXX", "[Computer name]", licenseBuffer, &licenseBufferSize);
    }

Important

On Android and iOS platforms, it is not possible, for reasons of confidentiality, to retrieve a truly unique hardware identifier. The side effect is that the hardware code is different (but fixed) for every application you develop, even on the same device.

Hint

We recommend that you activate the application the first time you run it, and then store the license on the device for future use.

Warning

Internet usage permission is required for the activation process.

## Checking the license

Before calling any function of the SDK, you need to check a valid license file first.

Before calling any function of the SDK, you need to check a valid license file first.

Python

    try:
        id3document.DocumentLicense.check_license(license_path)
        print(f"License name    : {id3document.DocumentLicense.get_license_name()}")
        print(f"License owner   : {id3document.DocumentLicense.get_license_owner()}")
        print(f"License serial  : {id3document.DocumentLicense.get_license_file_serial()}")
        print(f"License type    : {id3document.DocumentLicense.get_license_type().name}")
        print(f"Hardware code   : {id3document.DocumentLicense.get_license_file_hardware_code()}")
    except id3document.DocumentException as ex:
        print(f"License check failed: {ex}")

Dart

    try {
        DocumentLicense.checkLicense("id3Document.lic");
    }
    catch (DocumentException ex)
    {
        print(ex.message);
    }

C#

    try
    {
        DocumentLicense.CheckLicense("id3Document.lic");
    }
    catch (DocumentException ex)
    {
        Console.WriteLine(ex.Message);
    }

Java

    try {
        DocumentLicense.checkLicense("id3Document.lic");
    } catch (DocumentException ex) {
        System.out.println(ex.getMessage());
    }

Kotlin

    try {
        DocumentLicense.checkLicense("id3Document.lic")
    } catch (ex: DocumentException) {
        println(ex.message)
    }

C

    int err;

    err = id3DocumentLicense_CheckLicense("id3Document.lic", NULL);

    if (err == id3DocumentError_Success)
    {
    }

## See also

- License activation

- License hardware code

- DocumentLicense.activateSerialKey Method

- DocumentLicense.getHostHardwareCode Method