The following Java web service code example removes a policy
from a PDF document named PolicyProtectedLoanDoc.pdf. The
unsecured PDF document is saved as unProtectedLoan.pdf. (See Removing Policies from PDF Documents.)
/**
* Ensure that you create Java proxy files that consume
* the Rights Management 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 com.adobe.idp.services.*;
public class RemovePolicySwaRef {
public static void main(String[] args) {
try{
// Setting configurations to retrieve the Web service
String url = "http://hiro-xp:8080/soap/services/RightsManagementService?blob=swaRef";
String username = "administrator";
String password = "password";
// Create the RightsManagementServiceService object
RightsManagementServiceService rightsManagementService = new RightsManagementServiceService();
RightsManagementService rightsManagementClient = rightsManagementService.getRightsManagementService();
//Set connection properties required to invoke LiveCycle
((BindingProvider) rightsManagementClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
((BindingProvider) rightsManagementClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
((BindingProvider) rightsManagementClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
//Reference a policy-protected PDF document from which to remove a policy
String path = "C:\\Adobe\PolicyProtectedLoanDoc.pdf";
FileDataSource ds = new FileDataSource(path);
DataHandler handler = new DataHandler(ds);
BLOB inDoc = new BLOB();
inDoc.setSwaRef(handler);
//Remove a policy from the policy-protected PDF document
BLOB outDoc = rightsManagementClient.removePolicySecurity(inDoc);
//Write the PDF file to the local file system
File f = new File("C:\\Adobe\UnProtectedLoan.pdf");
BLOB outBlob = outDoc;
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();
}
}
}
|
|
|