The following Java code example prints an output stream
to a PostScript file named
MortgageForm.ps
. (See Printing
to Files.)
/**
* 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 AEM forms
*/
import java.io.*;
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 PrintToFileSwaRef{
public static void main(String[] args) {
try{
// Setting configurations to retrieve the Web service
String url = "http://[server]:[port]/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);
//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);
//Populate a byte array with BLOB data
BLOB outDoc = generatePrintedOutputResultDoc.value ;
DataHandler handler3 = outDoc.getSwaRef();
//Create a new file containing the returned PDF document
File f = new File("C:\\Adobe\Output.xml");
InputStream inputStream = handler3.getInputStream();
OutputStream out = new FileOutputStream(f);
//Iterate through the buffer
byte buf[] = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0)
out.write(buf, 0, len);
out.close();
inputStream.close();
System.out.println("The PostScript file was created. The Output.xml file contains the results.");
}catch (Exception ee)
{
ee.printStackTrace();
}
}
}
|
|
|