The following Java code example adds a signature field,
named SignatureField1, to a PDF document that is based on
a PDF file named Loan.pdf. The PDF document that contains
the new signature field is saved as a PDF file named LoanSig.pdf.
(See Adding 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 AddSignatureFieldSWAref {
public static void main(String[] args) {
try
{
//Set LiveCycle connection values
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);
//Specify a PDF document to which a signature field is added
String path1 = "C:\\Adobe\Loan.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 PositionRectangle object that specifies
//the signature fields location
PositionRectangle post = new PositionRectangle();
post.setLowerLeftX(193);
post.setLowerLeftY(47);
post.setWidth(133);
post.setHeight(12);
//Specify the page number that will contain the signature field
java.lang.Integer pageNum = new java.lang.Integer(1);
//Add a signature field to the PDF document
BLOB sigFieldPDF = signatureClient.addSignatureField(
inDoc,
fieldName,
pageNum,
post,
null,
null);
//Create a new file containing the returned PDF document
File f = new File("C:\\Adobe\LoanSig.pdf");
BLOB outBlob = sigFieldPDF;
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();
}
}
}
|
|
|