org.faceless.pdf2
Class AcrobatSignatureHandlerFactory

java.lang.Object
  extended by org.faceless.pdf2.AcrobatSignatureHandlerFactory
All Implemented Interfaces:
SignatureHandlerFactory

public class AcrobatSignatureHandlerFactory
extends Object
implements SignatureHandlerFactory

An implementation of SignatureHandlerFactory that returns handlers suitable for signing documents for use with Acrobat 6.0 or later.

For basic use it's quite acceptable to use the FormSignature.HANDLER_ACROBATSIX which is an instance of this factory. If advanced options need to be set (such as setting a TimeStamp server or changing the hash algorithm) then you can create an instance of this factory and set the options on that before passing it in to the FormSignature constructor.

Since:
2.7.1

Constructor Summary
AcrobatSignatureHandlerFactory()
          Create a new SignatureHandlerFactory
 
Method Summary
 SignatureHandler getHandler()
          Return a handler created by this factory
 void setContentSize(int size)
           This method can be called to fix the space allocated for the "Contents" variable, which contains the encoded signature.
 void setCustomAppearance(PDFCanvas canvas, float x1, float y1, float x2, float y2)
           Set a custom appearance for this signature.
 void setDigestAlgorithm(String algorithm)
          Set the message digest algorithm to use - one of MD5, SHA1, SHA256, SHA384, SHA512 or RIPEMD160 The default is SHA1.
 void setTimeStampServer(URL server)
          Specify the URL of an RFC3161 Timestamp Server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AcrobatSignatureHandlerFactory

public AcrobatSignatureHandlerFactory()
Create a new SignatureHandlerFactory

Method Detail

setDigestAlgorithm

public void setDigestAlgorithm(String algorithm)
Set the message digest algorithm to use - one of MD5, SHA1, SHA256, SHA384, SHA512 or RIPEMD160 The default is SHA1. Note that algorithms other than MD5 or SHA1 require Acrobat 8.0 or later, and may require a non-standard or more recent JCE provider (for instance, SHA256 was only added to the Sun JCE in version 1.6).

Parameters:
algorithm - the message-digest algorithm to use.

setTimeStampServer

public void setTimeStampServer(URL server)
Specify the URL of an RFC3161 Timestamp Server. If a server is specified, when the PDF is signed it will be contacted and the Signature timestamped. RFC3161 Timestamps can be verified in Acrobat 7 or later, and with this class via the various "TimeStamp" methods.

Parameters:
server - The server to contact for the TimeStamp. May be null to turn off timestamping (the default). If a username/password are required they may be specified in the URL, eg "http://user:password@server.com".
Since:
2.7.1
See Also:
FormSignature.getSignDate(), PKCS7SignatureHandler.getTimeStampCertificates()

setCustomAppearance

public void setCustomAppearance(PDFCanvas canvas,
                                float x1,
                                float y1,
                                float x2,
                                float y2)

Set a custom appearance for this signature. This method allows you to add a signature, thumbprint, logo or any other form of custom image to your signature annotations (technically, this method sets the "n2" layer of the annotation). The canvas may be of any size, and will be scaled to fit the annotation on the page.

Care needs to be taken when setting this value. It's not recommended to use a canvas containing a bitmap image with an opaque background, as this may mask any layers behind this one. In particular, a "?" is typically used on a layer below this one to indicate the signature has not been verified. Specifying an opaque image may result in this being obscured.

As a optional convenience, by specifying non-zero coordinates for the x1,y1,x2 and y2 values, some text describing the signing certificate will be added to the canvas at the specified location. The format for this is fixed, but as it doesn't have to be included, the developer is free to add his or her own text if they don't like the result, simply by setting all four values to zero.

As an example, the default PKCS7 appearance is set with the following code which loads a pre-defined pattern from a resources file:

   setCustomAppearance(new PDFCanvas("logo.Adobe", 1), 0, 35, 100, 65);
 

Parameters:
canvas - the canvas to display as the "n2" layer of the signature appearance.
x1 - the left-most X co-ordinate to place the (optional) certificate text
y1 - the bottom-most Y co-ordinate to place the (optional) certificate text
x2 - the right-most X co-ordinate to place the (optional) certificate text
y2 - the top-most Y co-ordinate to place the (optional) certificate text
Since:
2.7.3

setContentSize

public void setContentSize(int size)

This method can be called to fix the space allocated for the "Contents" variable, which contains the encoded signature. If a value > 0 is supplied then the Contents variable will have that much space allocated for it. If a value of <= 0 is supplied then the SignatureHandler.getEstimatedContentSize(int) method will be called with the negative of this value (so if you call setContentSize(-100), this will result in a call of getEstimatedContentSize(100).

The intention of this is to allocate space in the Contents variable for external objects, such as TimeStamps from a remote server. For instance, if you were using a PKCS7SignatureHandler to digitally sign and an RFC3161 TimeStamp server was specified, you could pass in a value of "-1000" to this method to reserve 1000 bytes in the PKCS#7 object for the TimeStamp token.

Parameters:
size - the size of the Contents string in bytes, or <= 0 to determine automatically.
Since:
2.7.6

getHandler

public SignatureHandler getHandler()
Description copied from interface: SignatureHandlerFactory
Return a handler created by this factory

Specified by:
getHandler in interface SignatureHandlerFactory


Copyright © 2001-2013 Big Faceless Organization