Skip to main content

axesWord Engine Automation

Introduction

Upon request, axes4 can provide a special version of axesWord that works without a user interface. This version can be fully automated and is intended for OEM partners of axes4.

Prerequisites

  1. The setup installs A4.Office.Automation.Jwt.dll in the axesWord Engine program folder. You must register this DLL in the .NET Framework GAC with the following command:
    regasm /tlb /codebase [PathToDLL]

    Depending on the .NET Framework version, regasm.exe is typically located here:
    64-bit: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe
    32-bit: C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm.exe
  2. A4.Office.Automation.Jwt.dll must be added as a reference to your solution.

Step-by-step instructions

  1. Make sure that A4.Office.Automation.JWT.dll is installed in the GAC (as described above).
  2. Create a Visual Studio project with .NET Framework 4.8.
  3. Add the following references:
    1. A4.Office.Automation.JWT.dll
    2. Office.dll (set "Embed Interop Types" to false in the properties)
    3. Microsoft.Office.Interop.Word.dll (set "Embed Interop Types" to false in the properties).

License workflow

Option 1: Code Signing Certificate

Overview

The license for axesWord Engine is bound to the Code Signing Certificate of your executable. At runtime, our licensing component checks whether axesWord Engine is being called from your executable and whether that executable is signed with the expected certificate.

This way, axesWord Engine runs on all systems where your product runs.

Process

  • You provide us with your application (*.exe), which is signed with a code signing certificate.
  • We issue you a token that is bound to this application and this certificate.

Code

using A4.Office.Automation.JWT;

public void DemoCodeSigningCertificate(Microsoft.Office.Interop.Word wordApplication) 
{
    var automationService = AutomationServiceFactory.Create(wordApplication, AuthorizationType.CodeCertificate);
    automationService.Authorization.Token = "[TOKEN]";  // assign the token provided by axes4.

    // Calls the Export function below
    Export(wordApplication, automationService);
}

Option 2: System (Machine) Identity

Overview

The license for axesWord Engine is bound to the executing machine. If you have a corresponding agreement with axes4, this process can be automated.

Process

  • Determine the System Identity of the executing machine (see code example below).
  • Using the System Identity, you can use our JWT Token Issue Server to automatically obtain a license token for this machine.

Code

using A4.Office.Automation.JWT;
using A4.Office.Automation.JWT.Validation;

public void DemoSystemIdentity(Microsoft.Office.Interop.Word wordApplication)
{
    var automationService = AutomationServiceFactory.Create(wordApplication, AuthorizationType.SystemIdentity);
    var systemIdentityContext = (ISystemIdentityAuthorizationContext)automationService.Authorization;
    
    // These are default values. Please contact axes4 for your specific scenario.
    var includeMacAdress = true;
    var includeActiveDirectoryDomainSid = false;
    var deviceFingerprintFactors = DeviceFingerprintFactors.SystemSerialNumber 
                                    | DeviceFingerprintFactors.SystemUuid
                                    | DeviceFingerprintFactors.BaseboardSerialNumber
                                    | DeviceFingerprintFactors.ProcessorId;

    var systemIdentity = systemIdentityContext.GetSystemIdentity(includeMacAdress, includeActiveDirectoryDomainSid, deviceFingerprintFactors);

    if (string.IsNullOrNothing(systemIdentity))
    {
        // Analyze error
        var error = addin.GetLastError();
    }

    service.Authorization.Token = "[TOKEN]";

    // Calls the Export function below
    Export(wordApplication, automationService);
}

Export

using A4.Office.Automation.JWT;
using A4.Office.Automation.JWT.Validation;
using System.Runtime.InteropServices;

public void Export(Microsoft.Office.Interop.Word wordApplication, IAutomationService automationService)
{
  var documents = wordApplication.Documents;
  var document = documents.Open("PathToYourDocument");

  try
  {
    var suppressFieldsUpdate = false;
    var suppressPagination = false;
    var exportAsPDFA = false;

    var result = automationService.Export("PathToTheExportedPdf", "YourTitle", "YourLanguage", suppressFieldsUpdate, suppressPagination, exportAsPDFA);

    if (result == AutomationResult.ErrorOccurred)
    {
        // Analyze error
        var error = automationService.GetLastError();
    }
  }
  finally
  {
    document.Close();

    Marshal.ReleaseComObject(document);
    Marshal.ReleaseComObject(documents);
  }
}

Return values

public enum AutomationResult
{
    Undefined = -1,
    Success = 0,
    WaitingForCompletion,
    ErrorOccured,

    AuthorizationUndefined,
    AuthorizationTokenMissing,
    AuthorizationTokenInvalid,
    AuthorizationFailed,

    OfficeApiDisconnected,

    DocumentNotOpen,
    DocumentNotActive,
    DocumentNotSaved,
    DocumentNotSavedLocal,
    DocumentCompatibilityModeActive,
    DocumentReadOnly,
}