Sending Print Streams to Printers

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

  • Zebra - ZPL

  • Intermec - IPL

  • Datamax - DPL

  • TecToshiba - TPCL

Using the Output service, you can merge XML data with a form design and output the form as a print stream. For example, you can create a PostScript print stream and send it to a network printer. The following illustration shows the Output service sending print streams to network printers.

注意: To demonstrate how to send a print stream to a network printer, this section sends a PostScript print stream to a network printer by using the SharedPrinter printer protocol.
注意: For more information about the Output service, see Services Reference for LiveCycle.

Summary of steps

To send a print stream to a network printer, 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

  5. Retrieve a document to print.

  6. Send the document to a network printer.

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.

Create an Output Client object

Before you can programmatically perform an Output service operation, 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 OutputServiceClient 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

You can set the run-time options when sending a print stream to a printer, including the following options:

  • Copies: Specifies the number of copies to send to the printer. The default value is 1.

  • Staple: An XCI option is set when a stapler is used. This option can be specified in the configuration model by the staple element and is used for PS and PCL printers only.

  • OutputJog: An XCI option is set when output pages should be jogged (physically shifted in the output tray). This option is for PS and PCL printers only.

  • OutputBin: XCI value that is used to enable the print driver to select the appropriate output bin.

注意: For information about all run-time options that you can set, see the PrintedOutputOptionsSpec class reference.

Retrieve a document to print

Retrieve a print stream to send to a printer. For example, you can retrieve a PostScript file and send it to a printer.

You can choose to send a PDF file if your printer supports PDF. However, an issue with sending a PDF document to a printer is that each printer manufacturer has a different implementation of the PDF interpreter. That is, some print manufacturers use Adobe PDF interpretation, but it depends on the printer. Other printers have their own PDF interpreter. As a result, printing results may vary.

Another limitation of sending a PDF document to a printer is that it just prints; it cannot access duplex, paper tray selection, and stapling, except through settings on the printer.

To retrieve a document to print, you use the generatePrintedOutput method. The following table specifies content types that are set for a given print stream when using the generatePrintedOutput method.

Print format

Description

DPL

Creates a dpl203.xdc by default or custom xdc output stream.

DPL300DPI

Creates a DPL 300 DPI output stream.

DPL406DPI

Creates a DPL 400 DPI output stream.

DPL600DPI

Creates a DPL 600 DPI output stream.

GenericColorPCL

Creates a Generic Color PCL (5c) output stream.

GenericPSLevel3

Creates a Generic PostScript Level 3 output stream.

IPL

Creates a Custom IPL output stream.

IPL300DPI

Creates a IPL 300 DPI output stream.

IPL400DPI

Creates a IPL 400 DPI output stream.

PCL

Creates a Generic Monochrome PCL (5e) output stream.

PostScript

Creates a Generic PostScript Level 2 output stream.

TPCL

Creates a Custom TPCL output stream.

TPCL305DPI

Creates a TPCL 305 DPI output stream.

TPCL600DPI

Creates a TPCL 600 DPI output stream.

ZPL

Creates a ZPL 203 DPI output stream.

ZPL300DPI

Creates a ZPL 300 DPI output stream.

注意: You can also send a print stream to a printer by using the generatePrintedOutput2 method. However the quick starts associated with the Sending Print Streams to Printers section use the generatePrintedOutput method.

Send the print stream to a network printer

After you retrieve a document to print, you can invoke the Output service, which causes it to send a print stream to a network printer. For the Output service to successfully locate the printer, you have to specify both the print server and the printer name. In addition, you must also specify the printing protocol.

注意: If PDFG is installed on the LiveCycle server and the server runs on Windows Server 2008, you cannot use the SharedPrinter property. In this situation, use a different printer protocol.
注意: If you are using a network printer and the access mechanism is SharedPrinter, you need to specify the complete network path of printer.Send a print stream to a network printer using the Java API

Send a print stream to a network printer by 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

    Create a PrintedOutputOptionsSpec object that represents print run-time options. For example, you can specify the number of copies to print by invoking the PrintedOutputOptionsSpec object’s setCopies method.

    注意: You cannot set the pagination value by using the PrintedOutputOptionsSpec object’s setPagination method if you are generating a ZPL print stream. Likewise, you cannot set the following options for a ZPL print stream: OutputJog, PageOffset, and Staple. ThesetPagination method is not valid for PostScript generation. It is valid only for PCL generation.
  5. Retrieve a document to print

    • Retrieve a document to print by invoking the OutputClient object’s generatePrintedOutput method and passing the following values:

      • A PrintFormat enumeration value that specifies the print stream. 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.

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

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

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

    • Create a com.adobe.idp.Document object to send to the printer by invoking the OutputResult object ‘s getGeneratedDoc method. This method returns a com.adobe.idp.Document object.

  6. Send the print stream to a network printer

    Send the print stream to a network printer by invoking the OutputClient object’s sendToPrinter method and passing the following values:

    • A com.adobe.idp.Document object that represents the print stream to send to the printer.

    • A PrinterProtocol enumeration value that specifies the printer protocol to use. For example, to specify the SharedPrinter protocol, pass PrinterProtocol.SharedPrinter.

    • A string value that specifies the name of the print server. For example, assuming the name of the print server is PrintSever1, pass\\\PrintSever1.

    • A string value that specifies the name of the printer. For example, assuming the name of the printer is Printer1, pass \\\PrintSever1\Printer1.

    注意: The sendToPrinter method was added to the LiveCycle API in version 8.2.1.

Send a print stream to a printer using the web service API

Send a print stream to a network printer by 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.

    注意: 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. Pass 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. Determine the byte array length 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 MTOM field with the contents of the byte array.

  4. Set print run-time options.

    Create a PrintedOutputOptionsSpec object by using its constructor. For example, you can 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 member.

    注意: You cannot set the pagination value by using the PrintedOutputOptionsSpec object’s pagination data member if you are generating a ZPL print stream. Likewise, you cannot set the following options for a ZPL print stream: OutputJog, PageOffset and Staple. Thepagination data member is not valid for PostScript generation. It is valid only for PCL generation.
  5. Retrieve a document to print.

    • Retrieve a document to print by invoking the OutputServiceService object’s generatePrintedOutput method and passing the following values:

      • A PrintFormat enumeration value that specifies the print stream. 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.

      • The PrintedOutputOptionsSpec object that contains print run-time options that are used when sending a print stream to a network printer.

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

      • A BLOB object that is populated by the generatePrintedOutput method. The generatePrintedOutput 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 generatePrintedOutput method. The generatePrintedOutput 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.)

    • Create a BLOB object to send to the printer by getting the value of the OutputResult object ‘s generatedDoc method. This method returns a BLOB object that contains PostScript data returned by the generatePrintedOutput method.

  6. Send the print stream to a network printer.

    Send the print stream to a network printer by invoking the OutputClient object’s sendToPrinter method and passing the following values:

    • A BLOB object that represents the print stream to send to the printer.

    • A PrinterProtocol enumeration value that specifies the printer protocol to use. For example, to specify the SharedPrinter protocol, pass PrinterProtocol.SharedPrinter.

    • A bool value that specifies whether to user the previous parameter value. Pass the value true. (This parameter value is required for web service invocation only.)

    • A string value that specifies the name of the print server. For example, assuming that the name of the print server is PrintSever1, pass \\\PrintSever1.

    • A string value that specifies the name of the printer. For example, assuming that the name of the printer is Printer1, pass \\\PrintSever1\Printer1.

    注意: The sendToPrinter method was added to the LiveCycle API in version 8.2.1.