package org.duanesworldtv.livecycle.samples;

/* * This Java Quick Start uses the following JAR files 
 * * 1. adobe-signatures-client.jar 
 * * 2. adobe-livecycle-client.jar 
 * * 3. adobe-usermanager-client.jar 
 * * 4. adobe-utilities.jar 
 * * 5. jbossall-client.jar 
 */ 
import java.util.*;
import java.io.File;
import java.io.FileInputStream;
import com.adobe.livecycle.signatures.client.*;
import com.adobe.livecycle.signatures.client.types.*;
import com.adobe.idp.Document;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactory;
import com.adobe.idp.dsc.clientsdk.ServiceClientFactoryProperties; 

public class AddSignatureField { 	
	public static void main(String[] args) {				
		try		{			
            //Set connection properties required to invoke LiveCycle ES                                           
	    	Properties ConnectionProps = new Properties();
	    	ConnectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_SOAP_ENDPOINT, "http://demo.ensemble.com:8080");
	    	ConnectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,ServiceClientFactoryProperties.DSC_SOAP_PROTOCOL);          
	    	ConnectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss");
	    	ConnectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "kvarsen");
	    	ConnectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password");			System.out.println("Connection Properties Set");
			
			//Create a ServiceClientFactory instance	
	    	//DON'T WORRY that you have a red X - we haven't added code yet ;-)
			ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps);
			//ServiceClientFactory myFactory = ServiceClientFactory.createInstance(connectionProps); 	
			
			//Create a SignatureServiceClient object		  
			SignatureServiceClient signClient = new SignatureServiceClient(myFactory);	
			
			//Specify a PDF document to which a signature field is added	
			//TODO: ensure you path below points at a PDF document.  It must be a static document (not possible to sign dynamic documents).
			FileInputStream fileInputStream = new FileInputStream("/Users/duane/Desktop/eclipse/workspace/JavaOne2009-docs/javaone2009test.pdf");			  
			Document inDoc = new Document (fileInputStream);  		  
			
			//TODO: Specify the name of the signature field		  
			
			
			//TODO: Create a  PositionRectangle object that specifies		  
			//the signature fields location	(int lowerLeftX, int lowerLeftY, int width, int height)	  
			
			
			//TODO: Specify the page number that will contain the signature field		  
			
			
		
			//Add a signature field to the PDF document		  
			Document sigFieldPDF = signClient.addSignatureField(		  	
					inDoc,		  	
					fieldName,		  	
					pageNum,		  	
					post,		  	
					null,		  	
					null); 		  
			
			//Save the PDF document that contains the signature field	
			//TODO: make sure this path is right for your machine!
			File outFile = new File("/Users/duane/Desktop/eclipse/workspace/JavaOne2009-docs/signatureadded.pdf");	
			sigFieldPDF.copyToFile(outFile);			
			System.out.println("Signature enabled PDF is saved at " + outFile);
		}catch (Exception ee){				
			ee.printStackTrace();			
		}	
	}
}

