Invoking LiveCycle ES services from an AIR applications

There are two ways to invoke a LiveCycle ES service from an AIR application: using webservices or using remoting. I’m a big fan of remoting over any kind of SOAP or REST services so I will write only about that, taking the Assembler service as an example. The Assembler service allows you to create PDF files from a variety of input documents – you can even merge pages between several documents, add watermarks, headers and much more.

The first step is to configure create your Flex project and add the required libraries. In order to use LiveCycle remoting you will need to add the library adobe-remoting-provider.swc located in LiveCycle8\LiveCycle_ES_SDK\misc\DataServices\Client-Libraries. Note that this path depends on your LiveCycle ES installation folder.

The second step is to call the AssemblerService but you’ll need to know the required parameters and how to pass them. For that one should go to the API reference, look for the AssemblerService interface and take a look at the invoke method

public AssemblerResult invoke(
Document ddx, Map inputs, AssemblerOptionSpec environment)

The first parameter is the DDX (Document Description XML) file describing the structure of the output document. The second one is a map with values referencing com.adobe.idp.Document objects and keys are the logical names from the DDX file.

In order to invoke this method from AIR all the input parameters should be wrapped in an ActionScript object that will act as HashMap – the key is the name of the parameter and the value is the actual value of it. If a parameter is missing from the map it will be considered null. In our case we will set only the first two parameters – the DDX file and the inputs map.

The code used to declare the remote object can be seen below

<mx:RemoteObject id=“AssemblerDocument”
destination=“AssemblerService”
showBusyCursor=“true”
fault=“assemblerFaultHandler(event)” result=“assemblerResultHandler(event);”/>

Next we should build the value for the input parameters: the DDX and the inputs map. The DDX specifies that the output PDF will be created by mixing two input PDF’s (the files are locally referenced, they are located on the same server as the LiveCycle ES server. In a real case you would probably use URL locations for them).

var ddx:XML=
<DDX xmlns=“http://ns.adobe.com/DDX/1.0/”>
  <PDF result=“PDFFinal.pdf”>
    <PDF source=“Dictionary Of Weightlifting.pdf” pages=“1-35″/>
    <PDF source=“Health.pdf” pages=“1-7″/>
    <PDF source=“Dictionary Of Weightlifting.pdf” pages=“36″/>
    <PDF source=“Health.pdf” pages=“8-33″/>
  </PDF>
</DDX>

var inDDXDoc:DocumentReference = new DocumentReference();
inDDXDoc.referenceType = DocumentReference.REF_TYPE_INLINE;
inDDXDoc.text = ddx.toXMLString();

var inputs:Object = new Object();

var documentRef:DocumentReference = new DocumentReference();
documentRef.referenceType = DocumentReference.REF_TYPE_FILE;
documentRef.fileRef = “C:\\tmp\\Dictionary Of Weightlifting.pdf”;
inputs["Dictionary Of Weightlifting.pdf"] = documentRef;

documentRef = new DocumentReference();
documentRef.referenceType = DocumentReference.REF_TYPE_FILE;
documentRef.fileRef = “C:\\tmp\\Health.pdf”;
inputs["Health.pdf"] = documentRef;

The final step is creating the input parameter map, setting the assembler credentials, and performing the asynchronous call

var parametersMap:Object = new Object();
parametersMap.inDDXDoc = inDDXDoc;
parametersMap.inputs = inputs;
AssemblerDocument.setCredentials(user, password);

var token:AsyncToken = AssemblerDocument.invokeDDX(parametersMap);
token.documentName = “Result.pdf”;

That’s all - As you can see it’s trivial to call the Assembler service from an AIR application. The most difficult part is figuring out the description of the input parameters and all the options related to the DDX format.

Leave a Reply