Creating PDF Documents Using Fragments

You can use the Output and Assembler services to create an output stream, such as a PDF document, that is based on fragments. The Assembler service assembles an XDP document that is based on fragments located in multiple XDP files. The assembled XDP document is passed to the Output service, which creates a PDF document. Although this workflow shows a PDF document being generated, the Output service can generate other output types, such as ZPL, for this workflow. A PDF document is used for discussion purposes only.

The following illustration shows this workflow.

Before reading Creating PDF Documents using Fragments , it is recommended that you become familiar with using the Assembler service to assemble multiple XDP documents. (See Assembling Multiple XDP Fragments .)

Note: You can also pass a form design assembled by the Assembler service to the Forms service instead of the Output service. The primary difference between the Output service and Forms service is that the Forms service generates interactive PDF documents and the Output service produces non-interactive PDF documents. Also the Forms service cannot generate printer-based output streams like ZPL.
Note: For more information about the Output service, see Services Reference for LiveCycle .

Summary of steps

To create a PDF document based on fragments, perform the following steps:

  1. Include project files.

  2. Create an Output and Assembler Client object.

  3. Use the Assembler service to generate the form design.

  4. Use the Output service to generate the PDF document.

  5. Save the PDF document as a PDF file.

Include project files

Include 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, make sure that you include the proxy files.

Create an Output and Assembler Client object

Before you can programmatically perform an Output service API operation, create an Output Client API object. Also, because this workflow invokes the Assembler service to create the form design, create an Assembler Client API object.

Use the Assembler service to generate the form design

Use the Assembler service to generate the form design using fragments. The Assembler service returns a com.adobe.idp.Document instance that contains the form design.

Use the Output service to generate the PDF document

You can use the Output service to generate a PDF document using the form design that the Assembler service created. Pass the com.adobe.idp.Document instance that the Assembler service returned to the Output service.

Save the PDF document as a PDF file

After the Output service generates a PDF document, you can save it as a PDF file.

Create a PDF document based on fragments using the Java API

Create a PDF document based on fragments by using the Output Service API and Assembler Service API (Java):

  1. Include project files.

    Include client JAR files, such as adobe-output-client.jar, in your Java project’s class path.

  2. Create an Output and Assembler Client object.

    • Create a ServiceClientFactory object that contains connection properties.

    • Create an OutputClient object by using its constructor and passing the ServiceClientFactory object.

    • Create an AssemblerServiceClient object by using its constructor and passing the ServiceClientFactory object.

  3. Use the Assembler service to generate the form design.

    Invoke the AssemblerServiceClient object’s invokeDDX method and pass the following required values:

    • A com.adobe.idp.Document object that represents the DDX document to use.

    • A java.util.Map object that contains the input XDP files.

    • 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 a com.adobe.livecycle.assembler.client.AssemblerResult object that contains the assembled XDP document. To retrieve the assembled XDP document, perform the following actions:

    • Invoke the AssemblerResult object’s getDocuments method. This method returns a java.util.Map object.

    • Iterate through the java.util.Map object until you find the resultant com.adobe.idp.Document object.

    • Invoke the com.adobe.idp.Document object’s copyToFile method to extract the assembled XDP document.

  4. Use the Output service to generate the PDF document.

    Invoke the OutputClient object’s generatePDFOutput2 method and pass the following values:

    • A TransformationFormat enumeration value. To generate a PDF document, specify TransformationFormat.PDF

    • A string value that specifies the content root where the additional resources, such as images, are located

    • A com.adobe.idp.Document object that represents the form design (use the instance returned by the Assembler service)

    • A PDFOutputOptionsSpec object that contains PDF run-time options

    • A RenderOptionsSpec object that contains rendering run-time options

    • The com.adobe.idp.Document object that contains the XML data source that contains data to merge with the form design

    The generatePDFOutput2 method returns an OutputResult object that contains the results of the operation

  5. Save the PDF document as a PDF file.

    • Retrieve a com.adobe.idp.Document object that represents the PDF document by invoking the OutputResult object’s getGeneratedDoc method.

    • Create a java.io.File object that contains the results of the operation. Ensure that the filename extension is .pdf.

    • Invoke the com.adobe.idp.Document object’s copyToFile method to copy the contents of the com.adobe.idp.Document object to the file. (Ensure that you use the com.adobe.idp.Document object that the getGeneratedDoc method returned.).

Create a PDF document based on fragments using the web service API

Create a PDF document based on fragments by using the Output Service API and Assembler Service API (web service):

  1. Include project files.

    Create a Microsoft .NET project that uses MTOM. Use the following WSDL definition for the service reference associated with the Output service:

    http://localhost:8080/soap/services/OutputService?WSDL&lc_version=9.0.1.

    Use the following WSDL definition for the service reference associated with the Assembler service:

    http://localhost:8080/soap/services/AssemblerService?WSDL&lc_version=9.0.1. 

    Because the BLOB data type is common to both service references, fully qualify the BLOB data type when using it. In the corresponding web service quick start, all BLOB instances are fully qualified.

    Note: Replace localhost with the IP address of the server hosting LiveCycle.
  2. Create an Output and Assembler Client object.

    • Create an OutputServiceClient object by using its default constructor.

    • Create an OutputServiceClient.Endpoint.Address object by using the System.ServiceModel.EndpointAddress constructor. Pass a string value that specifies the WSDL to the LiveCycle service (for example, http://localhost:8080/soap/services/OutputService?blob=mtom .) You do not need to use the lc_version attribute. This attribute is used when you create a service reference. However, specify ?blob=mtom to use MTOM.

    • Create a System.ServiceModel.BasicHttpBinding object by getting the value of the OutputServiceClient.Endpoint.Binding field. Cast the return value to BasicHttpBinding .

    • Set the System.ServiceModel.BasicHttpBinding object’s MessageEncoding field to WSMessageEncoding.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 OutputServiceClient.ClientCredentials.UserName.UserName field.

      • Assign the corresponding password value to the OutputServiceClient.ClientCredentials.UserName.Password field.

      • Assign the constant value HttpClientCredentialType.Basic to the BasicHttpBindingSecurity.Transport.ClientCredentialType field.

    • Assign the BasicHttpSecurityMode.TransportCredentialOnly constant value to the BasicHttpBindingSecurity.Security.Mode field.

    Note: Repeat these steps for the AssemblerServiceClient object.
  3. Use the Assembler service to generate the form design.

    Invoke the AssemblerServiceClient object’s invokeDDX method and pass the following values:

    • A BLOB object that represents the DDX document

    • The MyMapOf_xsd_string_To_xsd_anyType object that contains the required files

    • An AssemblerOptionSpec object that specifies run-time options

    The invokeDDX method returns an AssemblerResult object that contains the results of the job and any exceptions that occurred. To obtain the newly created XDP document, perform the following actions:

    • Access the AssemblerResult object’s documents field, which is a Map object that contains the resultant PDF documents.

    • Iterate through the Map object to retrieve the assembled form design. Cast that array member’s value to a BLOB . Pass this BLOB instance to the Output service.

  4. Use the Output service to generate the PDF document.

    Invoke the OutputServiceClient object’s generatePDFOutput2 method and pass the following values:

    • A TransformationFormat enumeration value. To generate a PDF document, specify TransformationFormat.PDF .

    • A string value that specifies the content root where the additional resources, such as images, are located.

    • A BLOB object that represents the form design (use the BLOB instance returned by the Assembler service).

    • A PDFOutputOptionsSpec object that contains PDF run-time options.

    • A RenderOptionsSpec object that contains rendering run-time options.

    • The BLOB object that contains the XML data source that contains data to merge with the form design.

    • An output BLOB object that the generatePDFOutput2 method populates. The generatePDFOutput2 method populates this object with generated metadata that describes the document. (This parameter value is required only for web service invocation).

    • An output OutputResult object that contains the results of the operation. (This parameter value is required only for web service invocation).

    The generatePDFOutput2 method returns a BLOB object that contains the non-interactive PDF form.

  5. Save the PDF document as a PDF file.

    • Create a System.IO.FileStream object by invoking its constructor. Pass a string value that represents the file location of the interactive PDF document and the mode in which to open the file.

    • Create a byte array that stores the content of the BLOB object retrieved from the generatePDFOutput2 method. Populate the byte array by getting the value of the BLOB object’s MTOM data member.

    • Create a System.IO.BinaryWriter object by invoking its constructor and passing the System.IO.FileStream object.

    • Write the contents of the byte array to a PDF file by invoking the System.IO.BinaryWriter object’s Write method and passing the byte array.

See also

Summary of steps

Quick Start (MTOM): Creating a PDF document based on fragments using the web service API

Invoking LiveCycle using MTOM

// Ethnio survey code removed