The following Java web service code example creates two
text patterns that the Output service searches for. The first text
pattern is Mortgage. If found, the Output service uses the form
design named Mortgage.xdp. The second text pattern is Automobile.
If found, the Output service uses the form design named AutomobileLoan.xdp.
If neither text pattern is located, the Output service uses the default
form design named Loan.xdp. The Loan.pdf is written
to the C:\Adobe folder located on the J2EE application server hosting
LiveCycle, not the client computer. (See Creating Search Rules.)
/**
* 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 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 CreateSearchRulesSwaRef {
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);
//Define two text patterns
Rule mortageRule = new Rule();
mortageRule.setPattern("Mortgage");
mortageRule.setForm("Mortgage.xdp");
Rule automobileRule = new Rule();
automobileRule.setPattern("Automobile");
automobileRule.setForm("AutomobileLoan.xdp");
//Add the Rules to a MyArrayOfXsdAnyType object
MyArrayOfXsdAnyType inputRules = new MyArrayOfXsdAnyType();
inputRules.getItem().add(mortageRule);
inputRules.getItem().add(automobileRule);
//Set PDF run-time options
PDFOutputOptionsSpec outputOptions = new PDFOutputOptionsSpec();
outputOptions.setFileURI("C:\\Adobe\Loan.pdf");
outputOptions.setLookAhead(300);
outputOptions.setRecordLevel(1);
outputOptions.setRules(inputRules);
//Set rendering run-time options
RenderOptionsSpec pdfOptions = new RenderOptionsSpec();
pdfOptions.setLinearizedPDF(true);
pdfOptions.setAcrobatVersion(AcrobatVersion.ACROBAT_8);
//Create Holders for the call to outClient
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.generatePDFOutput(
TransformationFormat.PDF,
"Loan.xdp",
"C:\\Adobe",
outputOptions,
pdfOptions,
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 PDF document was created. The Output.xml file contains the results.");
}catch (Exception ee)
{
ee.printStackTrace();
}
}
}
|
|
|