The following Java web service example converts a PDF document
named LoanSummary.pdf to an RTF document named LoanSummary.rtf.
(See Converting PDF Documents to Non-image Formats.)
/**
* 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 GeneratePdf_ExportPDFSwaRef {
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);
//Reference a PDF document to convert to RTF
String path1 = "C:\\Adobe\\LoanSummary.pdf";
FileDataSource ds1 = new FileDataSource(path1);
DataHandler handler1 = new DataHandler(ds1);
BLOB inDoc = new BLOB();
inDoc.setSwaRef(handler1);
//Prepare output parameters
Holder<BLOB> createdDocument = new Holder<BLOB>();
Holder<ExportPDFResult> result = new Holder<ExportPDFResult>();
//Convert a PDF document to a RTF document
pdfgClient.exportPDF2(
inDoc,
path1,
"RTF",
null,
result,
createdDocument) ;
////Save the converted RTF document
File f = new File("C:\\Adobe\LoanSummary.rtf");
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();
}
}
}
|
|
|