The following Java code example sends a PostScript print
stream to a network printer named \\Printer1\Printer. Two
copies are sent to the printer. (See Sending Print Streams to Printers .)
/**
* Ensure that you create Java proxy files that consume
* the Output services WSDL. You can use JAX-WS to create
* the proxy Java files.
*
* For information, see "Invoking LiveCycle using SwaRef" in Programming with LiveCycle
*/
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.Holder;
import com.adobe.idp.services.*;
public class SendToPrinterSwaRef{
public static void main(String[] args) {
try{
// Setting configurations to retrieve the Web service
String url = "http://hiro-xp:8080/soap/services/OutputService?blob=swaref";
String username = "administrator";
String password = "password";
// Create the service Client objects needed
OutputServiceService outService = new OutputServiceService();
OutputService outClient = outService.getOutputService();
//Set authentication values
((BindingProvider) outClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
((BindingProvider) outClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
((BindingProvider) outClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
//Create a BLOB object to store form data
String path = "C:\\Adobe\Loan.xml";
FileDataSource ds = new FileDataSource(path);
DataHandler handler = new DataHandler(ds);
BLOB inXMLData = new BLOB();
inXMLData.setSwaRef(handler);
//Set print run-time options required to print to a file
PrintedOutputOptionsSpec printOptions = new PrintedOutputOptionsSpec();
printOptions.setFileURI("C:\\Adobe\MortgageForm.ps");
printOptions.setLookAhead(300);
printOptions.setRecordLevel(1);
printOptions.setCopies(2);
//Create Holders for the call to generatePrintedOutput
Holder<BLOB> generatePrintedOutputPrintedDoc = new Holder<BLOB>();
Holder<BLOB> generatePrintedOutputMetaDataDoc = new Holder<BLOB>();
Holder<BLOB> generatePrintedOutputResultDoc = new Holder<BLOB>();
Holder<OutputResult> generatePrintedOutputResult = new Holder<OutputResult>();
//Create a PDF document
outClient.generatePrintedOutput(
PrintFormat.POST_SCRIPT,
"Loan.xdp",
"C:\\Adobe",
"C:\\Adobe",
printOptions,
inXMLData,
generatePrintedOutputPrintedDoc,
generatePrintedOutputMetaDataDoc,
generatePrintedOutputResultDoc,
generatePrintedOutputResult);
//Get the PostScript print stream to send to the printer
BLOB psPrintStream =generatePrintedOutputResult.value.getGeneratedDoc();
//Specify the print server and the printer name
String printServer = "\\\Printer1";
String printerName = "\\\Printer1\Printer";
//Send the PostScript print stream to the printer
outClient.sendToPrinter(
psPrintStream,
PrinterProtocol.SHARED_PRINTER,
printServer,
printerName);
System.out.println("The PostScript file was created. The Output.xml file contains the results.");
}catch (Exception ee)
{
ee.printStackTrace();
}
}
}
|
|
|