Dynamically Creating DDX Documents dynamically-creating-ddx-documents
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 be 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
Including AEM Forms Java library files
Programmatically Disassembling PDF Documents
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
ServiceClientFactory
object that contains connection properties. - Create an
AssemblerServiceClient
object by using its constructor and passing theServiceClientFactory
object.
- Create a
-
Create the DDX document.
-
Create a Java
DocumentBuilderFactory
object by calling theDocumentBuilderFactory
class’newInstance
method. -
Create a Java
DocumentBuilder
object by calling theDocumentBuilderFactory
object’snewDocumentBuilder
method. -
Call the
DocumentBuilder
object’snewDocument
method to instantiate aorg.w3c.dom.Document
object. -
Create the DDX document’s root element by invoking the
org.w3c.dom.Document
object’screateElement
method. This method creates anElement
object that represents the root element. Pass a string value representing the name of the element to thecreateElement
method. Cast the return value toElement
. Next, set a value for the child element by calling itssetAttribute
method. Finally, append the element to the header element by calling the header element’sappendChild
method, 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
PDFsFromBookmarks
element by calling theDocument
object’screateElement
method. Pass a string value representing the name of the element to thecreateElement
method. Cast the return value toElement
. Set a value for thePDFsFromBookmarks
element by calling itssetAttribute
method. Append thePDFsFromBookmarks
element to theDDX
element by calling the DDX element’sappendChild
method. Pass thePDFsFromBookmarks
element 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
PDF
element by calling theDocument
object’screateElement
method. Pass a string value that represents the element’s name. Cast the return value toElement
. Set a value for thePDF
element by calling itssetAttribute
method. Append thePDF
element to thePDFsFromBookmarks
element by calling thePDFsFromBookmarks
element’sappendChild
method. Pass thePDF
element 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.Transformer
object by invoking thejavax.xml.transform.Transformer
object’s staticnewInstance
method. - Create a
Transformer
object by invoking theTransformerFactory
object’snewTransformer
method. - Create a
ByteArrayOutputStream
object by using its constructor. - Create a
javax.xml.transform.dom.DOMSource
object by using its constructor. Pass theorg.w3c.dom.Document
object that represents the DDX document. - Create a
javax.xml.transform.dom.DOMSource
object by using its constructor and passing theByteArrayOutputStream
object. - Populate the Java
ByteArrayOutputStream
object by invoking thejavax.xml.transform.Transformer
object’stransform
method. Pass thejavax.xml.transform.dom.DOMSource
and thejavax.xml.transform.stream.StreamResult
objects. - Create a byte array and allocate the size of the
ByteArrayOutputStream
object to the byte array. - Populate the byte array by invoking the
ByteArrayOutputStream
object’stoByteArray
method. - Create a
com.adobe.idp.Document
object by using its constructor and passing the byte array.
- Create a
-
Reference a PDF document to disassemble.
-
Create a
java.util.Map
object that is used to store input PDF documents by using aHashMap
constructor. -
Create a
java.io.FileInputStream
object by using its constructor and passing the location of the PDF document to disassemble. -
Create a
com.adobe.idp.Document
object. Pass thejava.io.FileInputStream
object that contains the PDF document to disassemble. -
Add an entry to the
java.util.Map
object by invoking itsput
method 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.Document
object 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
AssemblerOptionSpec
object 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
AssemblerOptionSpec
object. For example, to instruct the Assembler service to continue processing a job when an error occurs, invoke theAssemblerOptionSpec
object’ssetFailOnError
method and passfalse
.
- Create an
-
Disassemble the PDF document.
Invoke the
AssemblerServiceClient
object’sinvokeDDX
method and pass the following values:- A
com.adobe.idp.Document
object that represents the dynamically created DDX document - A
java.util.Map
object that contains the PDF document to disassemble - A
com.adobe.livecycle.assembler.client.AssemblerOptionSpec
object that specifies the run-time options, including the default font and the job log level
The
invokeDDX
method returns acom.adobe.livecycle.assembler.client.AssemblerResult
object 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
AssemblerResult
object’sgetDocuments
method. This method returns ajava.util.Map
object. - Iterate through the
java.util.Map
object until you find the resultantcom.adobe.idp.Document
object. - Invoke the
com.adobe.idp.Document
object’scopyToFile
method to extract the PDF document.
- Invoke the
See also
Quick Start (SOAP mode): Dynamically creating a DDX document using the Java API
Including AEM Forms Java library files
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 localhost
with the IP address of the server hosting AEM Forms. -
Create a PDF Assembler client.
-
Create an
AssemblerServiceClient
object by using its default constructor. -
Create an
AssemblerServiceClient.Endpoint.Address
object by using theSystem.ServiceModel.EndpointAddress
constructor. 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_version
attribute. This attribute is used when you create a service reference. -
Create a
System.ServiceModel.BasicHttpBinding
object by getting the value of theAssemblerServiceClient.Endpoint.Binding
field. Cast the return value toBasicHttpBinding
. -
Set the
System.ServiceModel.BasicHttpBinding
object’sMessageEncoding
field 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.Basic
to the fieldBasicHttpBindingSecurity.Transport.ClientCredentialType
. - Assign the constant value
BasicHttpSecurityMode.TransportCredentialOnly
to the fieldBasicHttpBindingSecurity.Security.Mode
.
- Assign the AEM forms user name to the field
-
-
Create the DDX document.
-
Create a
System.Xml.XmlElement
object by using its constructor. -
Create the DDX document’s root element by invoking the
XmlElement
object’sCreateElement
method. This method creates anElement
object that represents the root element. Pass a string value representing the name of the element to theCreateElement
method. Set a value for the DDX element by calling itsSetAttribute
method. Finally, append the element to the DDX document by calling theXmlElement
object’sAppendChild
method. 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
PDFsFromBookmarks
element by calling theXmlElement
object’sCreateElement
method. Pass a string value representing the name of the element to theCreateElement
method. Next, set a value for the element by calling itsSetAttribute
method. Append thePDFsFromBookmarks
element to the root element by calling theDDX
element’sAppendChild
method. Pass thePDFsFromBookmarks
element 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
PDF
element by calling theXmlElement
object’sCreateElement
method. Pass a string value representing the name of the element to theCreateElement
method. Next, set a value for the child element by calling itsSetAttribute
method. Append thePDF
element to thePDFsFromBookmarks
element by calling thePDFsFromBookmarks
element’sAppendChild
method. Pass thePDF
element 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.MemoryStream
object by using its constructor. -
Populate the
MemoryStream
object with the DDX document by using theXmlElement
object that represents the DDX document. Invoke theXmlElement
object’sSave
method and pass theMemoryStream
object. -
Create a byte array and populate it with data located in the
MemoryStream
object. 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
BLOB
object. Assign the byte array to theBLOB
object’sMTOM
field.
-
-
Reference a PDF document to disassemble.
- Create a
BLOB
object by using its constructor. TheBLOB
object is used to store the input PDF document. ThisBLOB
object is passed to theinvokeOneDocument
as an argument. - Create a
System.IO.FileStream
object 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.FileStream
object. You can determine the size of the byte array by getting theSystem.IO.FileStream
object’sLength
property. - Populate the byte array with stream data by invoking the
System.IO.FileStream
object’sRead
method and passing the byte array, the starting position, and the stream length to read. - Populate the
BLOB
object by assigning itsMTOM
property the contents of the byte array.
- Create a
-
Set run-time options.
- Create an
AssemblerOptionSpec
object 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
AssemblerOptionSpec
object. For example, to instruct the Assembler service to continue processing a job when an error occurs, assignfalse
to theAssemblerOptionSpec
object’sfailOnError
data member.
- Create an
-
Disassemble the PDF document.
Invoke the
AssemblerServiceClient
object’sinvokeDDX
method and pass the following values:- A
BLOB
object that represents the dynamically created DDX document - The
mapItem
array that contains the input PDF document - An
AssemblerOptionSpec
object that specifies run-time options
The
invokeDDX
method returns anAssemblerResult
object 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
AssemblerResult
object’sdocuments
field, which is aMap
object that contains the disassembled PDF documents. - Iterate through the
Map
object to obtain each resultant document. Then, cast that array member’svalue
to aBLOB
. - Extract the binary data that represents the PDF document by accessing its
BLOB
object’sMTOM
property. This returns an array of bytes that you can write out to a PDF file.
- Access the
See also
Invoking AEM Forms using SwaRef