Printing to Files

You can use the Output service to print streams such as PostScript, Printer Control Language (PCL), or the following label formats to a file:

  • Zebra - ZPL

  • Intermec - IPL

  • Datamax - DPL

  • TecToshiba - TPCL

Using the Output service, you can merge XML data with a form design and print the form to a file. The following illustration shows the Output service creating laser and label files.

Note: For information about sending print streams to printers, see Sending Print Streams to Printers.
Note: For more information about the Output service, see Services Reference for LiveCycle.

Summary of steps

To print to a file, perform the following steps:

  1. Include project files.

  2. Create an Output Client object.

  3. Reference an XML data source.

  4. Set print run-time options required to print to a file.

  5. Print the print stream to a file.

  6. Retrieve the results of the operation.

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.

The following JAR files must be added to your project’s class path:

  • adobe-livecycle-client.jar

  • adobe-usermanager-client.jar

  • adobe-output-client.jar

  • adobe-utilities.jar (required if LiveCycle is deployed on JBoss)

  • jbossall-client.jar (required if LiveCycle is deployed on JBoss)

if LiveCycle is deployed on a supported J2EE application server that is not JBoss, you will need to replace the adobe-utilities.jar and jbossall-client.jar files with JAR files that are specific to the J2EE application server on which LiveCycle is deployed. (See Including LiveCycle Java library files.)

Create an Output Client object

Before you can programmatically perform an Output service operation, you must create an Output service client object. If you are using the Java API, create an OutputClient object. If you are using the Output web service API, create an OutputServiceService object.

Reference an XML data source

To print a document that contains data, you must reference an XML data source that contains XML elements for every form field that you want to populate with data. The XML element name must match the field name. An XML element is ignored if it does not correspond to a form field or if the XML element name does not match the field name. It is not necessary to match the order in which the XML elements are displayed if all XML elements are specified.

Set print run-time options required to print to a file

To print to a file, you must set the File URI run-time option by specifying the location and the name of the file to which the Output service prints. For example, to instruct the Output service to print a PostScript file named MortgageForm.ps to C:\Adobe, specify C:\Adobe\MortgageForm.ps.

Note: There are optional run-time options that you can define. For information about all the options that you can set, see the PrintedOutputOptionsSpec class reference in LiveCycle API Reference.

Print the print stream to a file

After you reference a valid XML data source that contains form data and you set print run-time options, you can invoke the Output service, which causes it to print a file.

Retrieve the results of the operation

After the Output service performs an operation, it returns various data items, such as XML data, that specifies whether the operation was successful.

Print to files using the Java API

Print to a file using the Output API (Java):

  1. Include project files.

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

  2. Create an Output Client object.

    • Create a ServiceClientFactory object that contains connection properties.

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

  3. Reference an XML data source.

    • Create a java.io.FileInputStream object that represents the XML data source that is used to populate the document by using its constructor and passing a string value that specifies the location of the XML file.

    • Create a com.adobe.idp.Document object by using its constructor and passing the java.io.FileInputStream object.

  4. Set print run-time options required to print to a file.

    • Create a PrintedOutputOptionsSpec object by using its constructor.

    • Specify the file by invoking the PrintedOutputOptionsSpec object’s setFileURI method and passing a string value that represents the name and location of the file. For example, if you want the Output service to print to a PostScript file named MortgageForm.ps located in C:\Adobe, specify C:\\Adobe\MortgageForm.ps.

    • Specify the number of copies to print by invoking the PrintedOutputOptionsSpec object’s setCopies method and passing an integer value that represents the number of copies.

  5. Print the print stream to a file.

    Print to a file by invoking the OutputClient object’s generatePrintedOutput method and passing the following values:

    • A PrintFormat enumeration value that specifies the print stream format to create. For example, to create a PostScript print stream, pass PrintFormat.PostScript.

    • A string value that specifies the name of the form design.

    • A string value that specifies the location of related collateral files such as image files.

    • A string value that specifies the location of the XDC file to use (you can pass null if you specified the XDC file to use by using the PrintedOutputOptionsSpec object).

    • The PrintedOutputOptionsSpec object that contains run-time options required to print to a file.

    • The com.adobe.idp.Document object that contain the XML data source that contains form data.

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

    Note: The OutputResult object’s getRecordLevelMetaDataList method returns null.
  6. Retrieve the results of the operation.

    • Create a com.adobe.idp.Document object that represents the status of the generatePrintedOutput method by invoking the OutputResult object’s getStatusDoc method (the OutputResult object was returned by the generatePrintedOutput method).

    • Create a java.io.File object that will contain the results of the operation. Ensure that the file extension is XML.

    • 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 was returned by the getStatusDoc method).

Print to files using the web service API

Print to a file using the Output API (web service):

  1. Include project files.

    Create a Microsoft .NET project that uses MTOM. Ensure that you use the following WSDL definition: http://localhost:8080/soap/services/OutputService?WSDL&lc_version=9.0.1.

    Note: Replace localhost with the IP address of the server hosting LiveCycle.
  2. Create an Output 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 LiveCycle user name to the field OutputServiceClient.ClientCredentials.UserName.UserName.

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

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

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

  3. Reference an XML data source.

    • Create a BLOB object by using its constructor. The BLOB object is used to store form data.

    • Create a System.IO.FileStream object by invoking its constructor and passing a string value that specifies the location of the XML file that contains form data.

    • 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 the System.IO.FileStream object’s Length property.

    • Populate the byte array with stream data by invoking the System.IO.FileStream object’s Read method and passing the byte array, the starting position, and the stream length to read.

    • Populate the BLOB object by assigning its binaryData property with the contents of the byte array.

  4. Set print run-time options required to print to a file.

    • Create a PrintedOutputOptionsSpec object by using its constructor.

    • Specify the file by assigning a string value that represents the location and name of the file to the PrintedOutputOptionsSpec object’s fileURI data member. For example, if you want the Output service to print to a PostScript file named MortgageForm.ps located in C:\Adobe, specify C:\\Adobe\MortgageForm.ps.

    • Specify the number of copies to print by assigning an integer value that represents the number of copies to the PrintedOutputOptionsSpec object’s copies data members.

  5. Print the print stream to a file.

    Print to a file by invoking the OutputServiceService object’s generatePrintedOutput method and passing the following values:

    • A PrintFormat enumeration value that specifies the print stream format to create. For example, to create a PostScript print stream, pass PrintFormat.PostScript.

    • A string value that specifies the name of the form design.

    • A string value that specifies the location of related collateral files such as image files.

    • A string value that specifies the location of the XDC file to use (you can pass null if you specified the XDC file to use by using the PrintedOutputOptionsSpec object).

    • The PrintedOutputOptionsSpec object that contains print run-time options required to print to a file.

    • The BLOB object that contains the XML data source that contains form data.

    • A BLOB object that is populated by the generatePDFOutput method. The generatePDFOutput method populates this object with generated metadata that describes the document. (This parameter value is required for web service invocation only.)

    • A BLOB object that is populated by the generatePDFOutput method. The generatePDFOutput method populates this object with result data. (This parameter value is required for web service invocation only.)

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

  6. Retrieve the results of the operation.

    • Create a System.IO.FileStream object by invoking its constructor and passing a string value that represents an XML file location that contains result data. Ensure that the file extension is XML.

    • Create a byte array that stores the data content of the BLOB object that was populated with result data by the OutputServiceService object’s generatePDFOutput method (the eighth parameter). 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 the XML file by invoking the System.IO.BinaryWriter object’s Write method and passing the byte array.

// Ethnio survey code removed