Quick Start (SwaRef): Removing usage rights from a PDF document using the web service API

The following Java code example removes usage rights from a rights-enabled PDF document named LoanUsageRights.pdf. (See Removing Usage Rights from 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 RemoveUsageRightsSWAref{ 
 
    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 usage rights from a rights-enabled PDF document   
            String path1 = "C:\\Adobe\LoanUsageRights.pdf"; 
            FileDataSource ds1 = new FileDataSource(path1);  
            DataHandler handler1 = new DataHandler(ds1); 
            BLOB inputPDF = new BLOB(); 
            inputPDF.setSwaRef(handler1); 
 
            //Remove usage rights from the PDF document 
            BLOB rightsEnabledPDF = readerExtensionClient.removeUsageRights(inputPDF);  
         
            //Create a new file containing the returned PDF document 
            File f = new File("C:\\Adobe\noUsageRightsLoan.pdf"); 
            DataHandler handler2 = rightsEnabledPDF.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(); 
        }     
    } 
}

// Ethnio survey code removed