The following Java web service code example applies usage
rights to a PDF document named Loan.pdf. The rights-enabled
PDF document is saved as a PDF file named LoanUsageRights.pdf.
The following usage rights are applied to this PDF document: enabledComments, enabledFormFillIn,
and enabledDigitalSignatures. (See Applying Usage Rights to PDF Documents.)
/**
* Ensure that you create Java proxy files that consume
* the Reader Extensions 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 java.io.InputStream;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.xml.ws.BindingProvider;
import com.adobe.idp.services.*;
public class ApplyUsageRightsSWAref{
public static void main(String[] args) {
try{
// Setting configurations to retrieve the Web service
String url = "http://hiro-xp:8080/soap/services/ReaderExtensionsService?blob=swaRef";
String username = "administrator";
String password = "password";
// Create the service Client objects needed
ReaderExtensionsServiceService readerExtensionService = new ReaderExtensionsServiceService();
ReaderExtensionsService readerExtensionClient = readerExtensionService.getReaderExtensionsService();
// Retrieve the Web services from the LiveCycle server.
((BindingProvider) readerExtensionClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
((BindingProvider) readerExtensionClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
((BindingProvider) readerExtensionClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
//Retrieve the PDF document to which to apply usage rights
//Set an input file as a BLOB
String path1 = "C:\\Adobe\Loan.pdf";
FileDataSource ds1 = new FileDataSource(path1);
DataHandler handler1 = new DataHandler(ds1);
BLOB inputPDF = new BLOB();
inputPDF.setSwaRef(handler1);
//Create a UsageRight object and specify specific usage rights
UsageRights useRight = new UsageRights();
useRight.setEnabledDynamicFormFields(true);
useRight.setEnabledComments(true);
useRight.setEnabledFormFillIn(true);
useRight.setEnabledDigitalSignatures(true);
//Create a ReaderExtensionsOptions object
ReaderExtensionsOptionSpec reOptions = new ReaderExtensionsOptionSpec();
//Set the usage rights
reOptions.setUsageRights(useRight);
reOptions.setMessage("This is a Rights-Enabled PDF Document");
//Apply usage rights to a PDF document
BLOB rightsEnabledPDF = readerExtensionClient.applyUsageRights(
inputPDF,
"RE2",
null,
reOptions);
//Create a new PDF file that represents the rights-enabled PDF document
File f = new File("C:\\Adobe\LoanUsageRights.pdf");
BLOB outBlob = rightsEnabledPDF;
DataHandler handler2 = outBlob.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();
}
}
}
|
|
|