Dynamically Creating DDX Documents dynamically-creating-ddx-documents
Samples and examples in this document are only for AEM Forms on JEE environment.
You can dynamically create a DDX document that can be used to perform an Assembler operation. Dynamically creating a DDX document enables you to use values in the DDX document that are obtained during run-time. To dynamically create a DDX document, use classes that belong to the programming language that you are using. For example, if you are developing your client application using Java, use classes that belong to the org.w3c.dom.*package. Likewise, if you are using Microsoft .NET, use classes that belong to the System.Xml namespace.
Before you can pass the DDX document to the Assembler service, convert the XML from an org.w3c.dom.Document instance to a com.adobe.idp.Document instance. If you are using web services, convert the XML from the data type used to create the XML(for example, XmlDocument) to a BLOB instance.
For this discussion, assume that the following DDX document is dynamically created.
<?xml version="1.0" encoding="UTF-8"?>
<DDX xmlns="https://ns.adobe.com/DDX/1.0/">
<PDFsFromBookmarks prefix="stmt">
<PDF source="AssemblerResultPDF.pdf"/>
</PDFsFromBookmarks>
</DDX>
This DDX document disassembles a PDF document. It is recommended that you are familiar with disassembling PDF documents.
Summary of steps summary-of-steps
To disassemble a PDF document by using a dynamically created DDX document, perform the following tasks:
- Include project files.
- Create a PDF Assembler client.
- Create the DDX document.
- Convert the DDX document.
- Set run-time options.
- Disassemble the PDF document.
- Save the disassembled PDF documents.
Include project files
Include the necessary files in your development project. If you are creating a client application by using Java, include the necessary JAR files. If you are using web services, ensure that you include the proxy files.
The following JAR files must be added to your project’s class path:
- adobe-livecycle-client.jar
- adobe-usermanager-client.jar
- adobe-assembler-client.jar
- adobe-utilities.jar (required if AEM Forms is deployed on JBoss)
- jbossall-client.jar (required if AEM Forms is deployed on JBoss)
Create a PDF Assembler client
Before you can programmatically perform an Assembler operation, create an Assembler service client.
Create the DDX document
Create a DDX document using the programming language that you are using. To create a DDX document that disassembles a PDF document, ensure that it contains the PDFsFromBookmarks element. Convert the data type used to create the DDX document to a com.adobe.idp.Document instance if you are using the Java API. If you are using web services, convert the data type to a BLOB instance.
Convert the DDX document
A DDX document that is created by using org.w3c.dom classes must be converted to a com.adobe.idp.Document object. To perform this task when using the Java API, use Java XML transform classes. If you are using web services, convert the DDX document to a BLOB object.
Reference a PDF document to disassemble
To disassemble a PDF document, reference a PDF file that represents the PDF document to disassemble. When passed to the Assembler service, a separate PDF document is returned for each level 1 bookmark in the document.
Set run-time options
You can set run-time options that control the behavior of the Assembler service while it performs a job. For example, you can set an option that instructs the Assembler service to continue processing a job if an error is encountered. To set run-time options, you use an AssemblerOptionSpec object.
Disassemble the PDF document
Disassemble the PDF document by invoking the invokeDDX operation. Pass the DDX document that was dynamically created. The Assembler service returns disassembled PDF documents within a collection object.
Save the disassembled PDF documents
All disassembled PDF documents are returned within a collection object. Iterate through the collection object and save each PDF document as a PDF file.
See also
Dynamically create a DDX document using the Java API
Dynamically create a DDX document using the web service API
Dynamically create a DDX document using the Java API dynamically-create-a-ddx-document-using-the-java-api
Dynamically create a DDX document and disassemble a PDF document by using the Assembler Service API (Java):
-
Include project files.
Include client JAR files, such as adobe-assembler-client.jar, in your Java project’s class path.
-
Create a PDF Assembler client.
- Create a
ServiceClientFactoryobject that contains connection properties. - Create an
AssemblerServiceClientobject by using its constructor and passing theServiceClientFactoryobject.
- Create a
-
Create the DDX document.
-
Create a Java
DocumentBuilderFactoryobject by calling theDocumentBuilderFactoryclass’newInstancemethod. -
Create a Java
DocumentBuilderobject by calling theDocumentBuilderFactoryobject’snewDocumentBuildermethod. -
Call the
DocumentBuilderobject’snewDocumentmethod to instantiate aorg.w3c.dom.Documentobject. -
Create the DDX document’s root element by invoking the
org.w3c.dom.Documentobject’screateElementmethod. This method creates anElementobject that represents the root element. Pass a string value representing the name of the element to thecreateElementmethod. Cast the return value toElement. Next, set a value for the child element by calling itssetAttributemethod. Finally, append the element to the header element by calling the header element’sappendChildmethod, and pass the child element object as an argument. The following lines of code show this application logic:Element root = (Element)document.createElement("DDX"); root.setAttribute("xmlns","https://ns.adobe.com/DDX/1.0/"); document.appendChild(root); -
Create the
PDFsFromBookmarkselement by calling theDocumentobject’screateElementmethod. Pass a string value representing the name of the element to thecreateElementmethod. Cast the return value toElement. Set a value for thePDFsFromBookmarkselement by calling itssetAttributemethod. Append thePDFsFromBookmarkselement to theDDXelement by calling the DDX element’sappendChildmethod. Pass thePDFsFromBookmarkselement object as an argument. The following lines of code show this application logic:Element PDFsFromBookmarks = (Element)document.createElement("PDFsFromBookmarks"); PDFsFromBookmarks.setAttribute("prefix","stmt"); root.appendChild(PDFsFromBookmarks); -
Create a
PDFelement by calling theDocumentobject’screateElementmethod. Pass a string value that represents the element’s name. Cast the return value toElement. Set a value for thePDFelement by calling itssetAttributemethod. Append thePDFelement to thePDFsFromBookmarkselement by calling thePDFsFromBookmarkselement’sappendChildmethod. Pass thePDFelement object as an argument. The following lines of code shows this application logic:Element PDF = (Element)document.createElement("PDF"); PDF.setAttribute("source","AssemblerResultPDF.pdf"); PDFsFromBookmarks.appendChild(PDF);
-
-
Convert the DDX document.
- Create a
javax.xml.transform.Transformerobject by invoking thejavax.xml.transform.Transformerobject’s staticnewInstancemethod. - Create a
Transformerobject by invoking theTransformerFactoryobject’snewTransformermethod. - Create a
ByteArrayOutputStreamobject by using its constructor. - Create a
javax.xml.transform.dom.DOMSourceobject by using its constructor. Pass theorg.w3c.dom.Documentobject that represents the DDX document. - Create a
javax.xml.transform.dom.DOMSourceobject by using its constructor and passing theByteArrayOutputStreamobject. - Populate the Java
ByteArrayOutputStreamobject by invoking thejavax.xml.transform.Transformerobject’stransformmethod. Pass thejavax.xml.transform.dom.DOMSourceand thejavax.xml.transform.stream.StreamResultobjects. - Create a byte array and allocate the size of the
ByteArrayOutputStreamobject to the byte array. - Populate the byte array by invoking the
ByteArrayOutputStreamobject’stoByteArraymethod. - Create a
com.adobe.idp.Documentobject by using its constructor and passing the byte array.
- Create a
-
Reference a PDF document to disassemble.
-
Create a
java.util.Mapobject that is used to store input PDF documents by using aHashMapconstructor. -
Create a
java.io.FileInputStreamobject by using its constructor and passing the location of the PDF document to disassemble. -
Create a
com.adobe.idp.Documentobject. Pass thejava.io.FileInputStreamobject that contains the PDF document to disassemble. -
Add an entry to the
java.util.Mapobject by invoking itsputmethod and passing the following arguments:- A string value that represents the key name. This value must match the value of the PDF source element specified in the DDX document. (In the DDX document that is dynamically created, the value is
AssemblerResultPDF.pdf.) - A
com.adobe.idp.Documentobject that contains the PDF document to disassemble.
- A string value that represents the key name. This value must match the value of the PDF source element specified in the DDX document. (In the DDX document that is dynamically created, the value is
-
-
Set run-time options.
- Create an
AssemblerOptionSpecobject that stores run-time options by using its constructor. - Set run-time options to meet your business requirements by invoking a method that belongs to the
AssemblerOptionSpecobject. For example, to instruct the Assembler service to continue processing a job when an error occurs, invoke theAssemblerOptionSpecobject’ssetFailOnErrormethod and passfalse.
- Create an
-
Disassemble the PDF document.
Invoke the
AssemblerServiceClientobject’sinvokeDDXmethod and pass the following values:- A
com.adobe.idp.Documentobject that represents the dynamically created DDX document - A
java.util.Mapobject that contains the PDF document to disassemble - A
com.adobe.livecycle.assembler.client.AssemblerOptionSpecobject that specifies the run-time options, including the default font and the job log level
The
invokeDDXmethod returns acom.adobe.livecycle.assembler.client.AssemblerResultobject that contains the disassembled PDF documents and any exceptions that occurred. - A
-
Save the disassembled PDF documents.
To obtain the disassembled PDF documents, perform the following actions:
- Invoke the
AssemblerResultobject’sgetDocumentsmethod. This method returns ajava.util.Mapobject. - Iterate through the
java.util.Mapobject until you find the resultantcom.adobe.idp.Documentobject. - Invoke the
com.adobe.idp.Documentobject’scopyToFilemethod to extract the PDF document.
- Invoke the
See also
Quick Start (SOAP mode): Dynamically creating a DDX document using the Java API
Dynamically create a DDX document using the web service API dynamically-create-a-ddx-document-using-the-web-service-api
Dynamically create a DDX document and disassemble a PDF document by using the Assembler Service API (web service):
-
Include project files.
Create a Microsoft .NET project that uses MTOM. Ensure that you use the following WSDL definition when setting a service reference:
http://localhost:8080/soap/services/AssemblerService?WSDL&lc_version=9.0.1.note note NOTE Replace localhostwith the IP address of the server hosting AEM Forms. -
Create a PDF Assembler client.
-
Create an
AssemblerServiceClientobject by using its default constructor. -
Create an
AssemblerServiceClient.Endpoint.Addressobject by using theSystem.ServiceModel.EndpointAddressconstructor. Pass a string value that specifies the WSDL to the AEM Forms service (for example,http://localhost:8080/soap/services/AssemblerService?blob=mtom). You do not need to use thelc_versionattribute. This attribute is used when you create a service reference. -
Create a
System.ServiceModel.BasicHttpBindingobject by getting the value of theAssemblerServiceClient.Endpoint.Bindingfield. Cast the return value toBasicHttpBinding. -
Set the
System.ServiceModel.BasicHttpBindingobject’sMessageEncodingfield toWSMessageEncoding.Mtom. This value ensures that MTOM is used. -
Enable basic HTTP authentication by performing the following tasks:
- Assign the AEM forms user name to the field
AssemblerServiceClient.ClientCredentials.UserName.UserName. - Assign the corresponding password value to the field
AssemblerServiceClient.ClientCredentials.UserName.Password. - Assign the constant value
HttpClientCredentialType.Basicto the fieldBasicHttpBindingSecurity.Transport.ClientCredentialType. - Assign the constant value
BasicHttpSecurityMode.TransportCredentialOnlyto the fieldBasicHttpBindingSecurity.Security.Mode.
- Assign the AEM forms user name to the field
-
-
Create the DDX document.
-
Create a
System.Xml.XmlElementobject by using its constructor. -
Create the DDX document’s root element by invoking the
XmlElementobject’sCreateElementmethod. This method creates anElementobject that represents the root element. Pass a string value representing the name of the element to theCreateElementmethod. Set a value for the DDX element by calling itsSetAttributemethod. Finally, append the element to the DDX document by calling theXmlElementobject’sAppendChildmethod. Pass the DDX object as an argument. The following lines of code show this application logic:System.Xml.XmlElement root = ddx.CreateElement("DDX"); root.SetAttribute("xmlns", "https://ns.adobe.com/DDX/1.0/"); ddx.AppendChild(root); -
Create the DDX document’s
PDFsFromBookmarkselement by calling theXmlElementobject’sCreateElementmethod. Pass a string value representing the name of the element to theCreateElementmethod. Next, set a value for the element by calling itsSetAttributemethod. Append thePDFsFromBookmarkselement to the root element by calling theDDXelement’sAppendChildmethod. Pass thePDFsFromBookmarkselement object as an argument. The following lines of code show this application logic:XmlElement PDFsFromBookmarks = ddx.CreateElement("PDFsFromBookmarks"); PDFsFromBookmarks.SetAttribute("prefix", "stmt"); root.AppendChild(PDFsFromBookmarks); -
Create the DDX document’s
PDFelement by calling theXmlElementobject’sCreateElementmethod. Pass a string value representing the name of the element to theCreateElementmethod. Next, set a value for the child element by calling itsSetAttributemethod. Append thePDFelement to thePDFsFromBookmarkselement by calling thePDFsFromBookmarkselement’sAppendChildmethod. Pass thePDFelement object as an argument. The following lines of code shows this application logic:XmlElement PDF = ddx.CreateElement("PDF"); PDF.SetAttribute("source", "AssemblerResultPDF.pdf"); PDFsFromBookmarks.AppendChild(PDF);
-
-
Convert the DDX document.
-
Create a
System.IO.MemoryStreamobject by using its constructor. -
Populate the
MemoryStreamobject with the DDX document by using theXmlElementobject that represents the DDX document. Invoke theXmlElementobject’sSavemethod and pass theMemoryStreamobject. -
Create a byte array and populate it with data in the
MemoryStreamobject. The following code shows this application logic:int bufLen = Convert.ToInt32(stream.Length); byte[] byteArray = new byte[bufLen]; stream.Position = 0; int count = stream.Read(byteArray, 0, bufLen); -
Create a
BLOBobject. Assign the byte array to theBLOBobject’sMTOMfield.
-
-
Reference a PDF document to disassemble.
- Create a
BLOBobject by using its constructor. TheBLOBobject is used to store the input PDF document. ThisBLOBobject is passed to theinvokeOneDocumentas an argument. - Create a
System.IO.FileStreamobject by invoking its constructor. Pass a string value that represents the file location of the input PDF document and the mode in which to open the file. - Create a byte array that stores the content of the
System.IO.FileStreamobject. You can determine the size of the byte array by getting theSystem.IO.FileStreamobject’sLengthproperty. - Populate the byte array with stream data by invoking the
System.IO.FileStreamobject’sReadmethod and passing the byte array, the starting position, and the stream length to read. - Populate the
BLOBobject by assigning itsMTOMproperty the contents of the byte array.
- Create a
-
Set run-time options.
- Create an
AssemblerOptionSpecobject that stores run-time options by using its constructor. - Set run-time options to meet your business requirements by assigning a value to a data member that belongs to the
AssemblerOptionSpecobject. For example, to instruct the Assembler service to continue processing a job when an error occurs, assignfalseto theAssemblerOptionSpecobject’sfailOnErrordata member.
- Create an
-
Disassemble the PDF document.
Invoke the
AssemblerServiceClientobject’sinvokeDDXmethod and pass the following values:- A
BLOBobject that represents the dynamically created DDX document - The
mapItemarray that contains the input PDF document - An
AssemblerOptionSpecobject that specifies run-time options
The
invokeDDXmethod returns anAssemblerResultobject that contains the results of the job and any exceptions that occurred. - A
-
Save the disassembled PDF documents.
To obtain the newly created PDF documents, perform the following actions:
- Access the
AssemblerResultobject’sdocumentsfield, which is aMapobject that contains the disassembled PDF documents. - Iterate through the
Mapobject to obtain each resultant document. Then, cast that array member’svalueto aBLOB. - Extract the binary data that represents the PDF document by accessing its
BLOBobject’sMTOMproperty. This returns an array of bytes that you can write out to a PDF file.
- Access the
See also
Invoking AEM Forms using SwaRef