Quick Start (SwaRef): Modifying a signature field using the web service API

The following Java web service code example modifies a signature field named SignatureField1 by locking all fields in the form when a signature is applied to the signature field and ensuring that no changes are allowed. After the Signature service returns the PDF document that contains the modified signature field, the PDF document is saved as a PDF file named LoanSig.pdf. (This example overwrites the PDF file that is passed to the Signature service.) (See Modifying Signature Fields.)

/** 
    * Ensure that you create Java proxy files that consume 
    * the Signature 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.File; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.io.InputStream; 
import java.io.OutputStream; 
 
import javax.activation.DataHandler; 
import javax.activation.FileDataSource; 
import javax.xml.ws.BindingProvider; 
 
import com.adobe.idp.services.*; 
 
public class ModifySignatureFieldSWAref { 
     
    public static void main(String[] args) { 
         
    try 
    { 
        //Set connection settings 
        String url = "http://hiro-xp:8080/soap/services/signatureservice?blob=swaRef"; 
        String username = "administrator"; 
        String password = "password"; 
             
        // Create the service Client objects needed 
        SignatureServiceService signatureService = new SignatureServiceService(); 
        SignatureService signatureClient =  signatureService.getSignatureservice(); 
     
        // Retrieve the Web services from the LiveCycle server. 
        ((BindingProvider) signatureClient).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url); 
        ((BindingProvider) signatureClient).getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username); 
        ((BindingProvider) signatureClient).getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password); 
             
        //Set an input file as a BLOB         
        String path1 = "C:\\Adobe\LoanSig.pdf"; 
        FileDataSource ds1 = new FileDataSource(path1);  
        DataHandler handler1 = new DataHandler(ds1); 
        BLOB inDoc = new BLOB(); 
        inDoc.setSwaRef(handler1); 
         
        //Specify the name of the signature field 
        String fieldName = "SignatureField1"; 
         
        //Create a PDFSignatureFieldProperties 
        PDFSignatureFieldProperties fieldProperties = new PDFSignatureFieldProperties(); 
         
         //Create a PDFSeedValueOptionSpec object that stores  
         //seed value dictionary information. 
         PDFSeedValueOptionSpec seedOptionsSpec = new PDFSeedValueOptionSpec(); 
         
         //Disallow changes to the PDF document. Any change to the document invalidates  
         //the signature 
         seedOptionsSpec.setMdpValue(MDPPermissions.NO_CHANGES); 
         
         //Create a FieldMDPOptionSpec object that stores  
         //signature field lock dictionary information. 
         FieldMDPOptionSpec fieldMDPOptionsSpec = new FieldMDPOptionSpec();     
         
         //Lock all fields in the PDF document 
         fieldMDPOptionsSpec.setAction(FieldMDPAction.ALL); 
         
         //Set dictionary information 
         fieldProperties.setSeedValue(seedOptionsSpec); 
         fieldProperties.setFieldMDP(fieldMDPOptionsSpec); 
                 
         //Modify the signature field 
         BLOB modSignatureField =  signatureClient.modifySignatureField(inDoc,fieldName,fieldProperties); 
 
         //Create a new file containing the returned PDF document 
        File f = new File("C:\\Adobe\Loan.pdf"); 
        BLOB outBlob = modSignatureField; 
        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 ee) 
      { 
        ee.printStackTrace(); 
      } 
    } 
}

// Ethnio survey code removed