The following Java web service example converts a Word
file named Loan.doc to a PDF document named Loan.pdf.
(See Converting Word Documents to PDF Documents.)
/**
* Ensure that you create Java proxy files that consume
* the Encryption 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 ConvertWordDocumentSwaRef {
public static void main(String[] args) {
try{
// Setting configurations to retrieve the Web service
String url = "http://pdf-generator:8080/soap/services/GeneratePDFService?blob=swaRef";
String username = "administrator";
String password = "password";
// Create the service Client objects needed
GeneratePDFServiceService pdfgService = new GeneratePDFServiceService();
GeneratePDFService pdfgClient = pdfgService.getGeneratePDFService();
// Retrieve the Web services from the LiveCycle Server.
((BindingProvider) pdfgClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
((BindingProvider) pdfgClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
((BindingProvider) pdfgClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
//Get the PDF document
String path1 = "C:\\Adobe\Loan.pdf";
FileDataSource ds1 = new FileDataSource(path1);
DataHandler handler1 = new DataHandler(ds1);
BLOB inDoc = new BLOB();
inDoc.setSwaRef(handler1);
//Set createPDF2 parameter values
String adobePDFSettings = "Standard";
String securitySettings = "No Security";
//Prepare output parameters
Holder<BLOB> logDocument = new Holder<BLOB>();
Holder<BLOB> createdDocument = new Holder<BLOB>();
Holder<CreatePDFResult> result = new Holder<CreatePDFResult>();
//Convert the Word document to a PDF document
pdfgClient.createPDF2(
inDoc,
"DOC",
null,
adobePDFSettings,
securitySettings,
null,
null,
result,
createdDocument,
logDocument) ;
//Save the converted PDF document as a PDF file
File f = new File("C:\\Adobe\Loan.pdf");
DataHandler handler2 = createdDocument.value.getSwaRef();
//Get an InputStream from DataHandler and
//write to a file
InputStream inputStream = handler2.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();
}catch (Exception e) {
e.printStackTrace();
}
}
}
|
|
|