|
![]() |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lowagie.text.pdf.PdfSignatureAppearance
public class PdfSignatureAppearance
This class takes care of the cryptographic options and appearances that form a signature.
Nested Class Summary | |
---|---|
private static class |
PdfSignatureAppearance.RangeStream
|
static interface |
PdfSignatureAppearance.SignatureEvent
An interface to retrieve the signature dictionary for modification. |
Field Summary | |
---|---|
private boolean |
acro6Layers
Holds value of property acro6Layers. |
private PdfTemplate[] |
app
|
private byte[] |
bout
|
private int |
boutLen
|
private Certificate[] |
certChain
|
private int |
certificationLevel
|
static int |
CERTIFIED_FORM_FILLING
|
static int |
CERTIFIED_FORM_FILLING_AND_ANNOTATIONS
|
static int |
CERTIFIED_NO_CHANGES_ALLOWED
|
private String |
contact
Holds value of property contact. |
private CRL[] |
crlList
|
private PdfDictionary |
cryptoDictionary
|
private String |
digestEncryptionAlgorithm
|
private HashMap |
exclusionLocations
|
private byte[] |
externalDigest
|
private byte[] |
externalRSAdata
|
private String |
fieldName
|
private PdfName |
filter
|
private PdfTemplate |
frm
|
private Image |
image
Holds value of property image. |
private float |
imageScale
Holds value of property imageScale. |
private Font |
layer2Font
Holds value of property layer2Font. |
private String |
layer2Text
|
private String |
layer4Text
Holds value of property layer4Text. |
private String |
location
|
private static float |
MARGIN
|
private boolean |
newField
|
static int |
NOT_CERTIFIED
|
private OutputStream |
originalout
|
private int |
page
|
private Rectangle |
pageRect
|
private boolean |
preClosed
|
private PrivateKey |
privKey
|
private String |
provider
|
static String |
questionMark
Commands to draw a yellow question mark in a stream content |
private RandomAccessFile |
raf
|
private int[] |
range
|
private String |
reason
|
private Rectangle |
rect
|
private int |
render
|
private int |
runDirection
Holds value of property runDirection. |
static PdfName |
SELF_SIGNED
The self signed filter. |
private PdfSignatureAppearance.SignatureEvent |
signatureEvent
Holds value of property signatureEvent. |
private Image |
signatureGraphic
|
static int |
SignatureRenderDescription
The rendering mode is just the description |
static int |
SignatureRenderGraphicAndDescription
The rendering mode is an image and the description |
static int |
SignatureRenderNameAndDescription
The rendering mode is the name of the signer and the description |
private Calendar |
signDate
|
private ByteBuffer |
sigout
|
private PdfSigGenericPKCS |
sigStandard
|
private PdfStamper |
stamper
|
private File |
tempFile
|
private static float |
TOP_SECTION
|
static PdfName |
VERISIGN_SIGNED
The VeriSign filter. |
static PdfName |
WINCER_SIGNED
The Windows Certificate Security. |
private PdfStamperImp |
writer
|
Constructor Summary | |
---|---|
PdfSignatureAppearance(PdfStamperImp writer)
|
Method Summary | |
---|---|
private void |
addDocMDP(PdfDictionary crypto)
|
void |
close(PdfDictionary update)
This is the last method to be called when using external signatures. |
static float |
fitText(Font font,
String text,
Rectangle rect,
float maxFontSize,
int runDirection)
Fits the text to some rectangle adjusting the font size as needed. |
PdfTemplate |
getAppearance()
Gets the main appearance layer. |
Certificate[] |
getCertChain()
Gets the certificate chain. |
int |
getCertificationLevel()
Gets the certified status of this document. |
String |
getContact()
Gets the signing contact. |
CRL[] |
getCrlList()
Gets the certificate revocation list. |
PdfDictionary |
getCryptoDictionary()
Gets the user made signature dictionary. |
String |
getFieldName()
Gets the field name. |
PdfName |
getFilter()
Gets the filter used to sign the document. |
Image |
getImage()
Gets the background image for the layer 2. |
float |
getImageScale()
Gets the scaling to be applied to the background image. |
PdfTemplate |
getLayer(int layer)
Gets a template layer to create a signature appearance. |
Font |
getLayer2Font()
Gets the n2 and n4 layer font. |
String |
getLayer2Text()
Gets the signature text identifying the signer if set by setLayer2Text(). |
String |
getLayer4Text()
Gets the text identifying the signature status if set by setLayer4Text(). |
String |
getLocation()
Gets the signing location. |
String |
getNewSigName()
Gets a new signature fied name that doesn't clash with any existing name. |
(package private) OutputStream |
getOriginalout()
|
int |
getPage()
Gets the page number of the field. |
Rectangle |
getPageRect()
Gets the rectangle that represent the position and dimension of the signature in the page. |
PrivateKey |
getPrivKey()
Gets the private key. |
String |
getProvider()
Returns the Cryptographic Service Provider that will sign the document. |
InputStream |
getRangeStream()
Gets the document bytes that are hashable when using external signatures. |
String |
getReason()
Gets the signing reason. |
Rectangle |
getRect()
Gets the rectangle representing the signature dimensions. |
int |
getRender()
Gets the rendering mode for this signature. |
int |
getRunDirection()
Gets the run direction. |
PdfSignatureAppearance.SignatureEvent |
getSignatureEvent()
Getter for property signatureEvent. |
Image |
getSignatureGraphic()
Gets the Image object to render. |
Calendar |
getSignDate()
Gets the signature date. |
(package private) ByteBuffer |
getSigout()
|
PdfSigGenericPKCS |
getSigStandard()
Gets the instance of the standard signature dictionary. |
PdfStamper |
getStamper()
Gets the PdfStamper associated with this instance. |
File |
getTempFile()
Gets the temporary file. |
PdfTemplate |
getTopLayer()
Gets the template that aggregates all appearance layers. |
boolean |
isAcro6Layers()
Gets the Acrobat 6.0 layer mode. |
boolean |
isInvisible()
Gets the visibility status of the signature. |
boolean |
isNewField()
Checks if a new field was created. |
boolean |
isPreClosed()
Checks if the document is in the process of closing. |
void |
preClose()
This is the first method to be called when using external signatures. |
void |
preClose(HashMap exclusionSizes)
This is the first method to be called when using external signatures. |
void |
setAcro6Layers(boolean acro6Layers)
Acrobat 6.0 and higher recommends that only layer n2 and n4 be present. |
void |
setCertificationLevel(int certificationLevel)
Sets the document type to certified instead of simply signed. |
void |
setContact(String contact)
Sets the signing contact. |
void |
setCrypto(PrivateKey privKey,
Certificate[] certChain,
CRL[] crlList,
PdfName filter)
Sets the cryptographic parameters. |
void |
setCryptoDictionary(PdfDictionary cryptoDictionary)
Sets a user made signature dictionary. |
void |
setExternalDigest(byte[] digest,
byte[] RSAdata,
String digestEncryptionAlgorithm)
Sets the digest/signature to an external calculated value. |
void |
setImage(Image image)
Sets the background image for the layer 2. |
void |
setImageScale(float imageScale)
Sets the scaling to be applied to the background image. |
void |
setLayer2Font(Font layer2Font)
Sets the n2 and n4 layer font. |
void |
setLayer2Text(String text)
Sets the signature text identifying the signer. |
void |
setLayer4Text(String text)
Sets the text identifying the signature status. |
void |
setLocation(String location)
Sets the signing location. |
(package private) void |
setOriginalout(OutputStream originalout)
|
void |
setProvider(String provider)
Sets the Cryptographic Service Provider that will sign the document. |
void |
setReason(String reason)
Sets the signing reason. |
void |
setRender(int render)
Sets the rendering mode for this signature. |
void |
setRunDirection(int runDirection)
Sets the run direction in the n2 and n4 layer. |
void |
setSignatureEvent(PdfSignatureAppearance.SignatureEvent signatureEvent)
Sets the signature event to allow modification of the signature dictionary. |
void |
setSignatureGraphic(Image signatureGraphic)
Sets the Image object to render when Render is set to SignatureRenderGraphicAndDescription |
void |
setSignDate(Calendar signDate)
Sets the signature date. |
(package private) void |
setSigout(ByteBuffer sigout)
|
(package private) void |
setStamper(PdfStamper stamper)
|
(package private) void |
setTempFile(File tempFile)
|
void |
setVisibleSignature(Rectangle pageRect,
int page,
String fieldName)
Sets the signature to be visible. |
void |
setVisibleSignature(String fieldName)
Sets the signature to be visible. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int SignatureRenderDescription
public static final int SignatureRenderNameAndDescription
public static final int SignatureRenderGraphicAndDescription
public static final PdfName SELF_SIGNED
public static final PdfName VERISIGN_SIGNED
public static final PdfName WINCER_SIGNED
public static final int NOT_CERTIFIED
public static final int CERTIFIED_NO_CHANGES_ALLOWED
public static final int CERTIFIED_FORM_FILLING
public static final int CERTIFIED_FORM_FILLING_AND_ANNOTATIONS
private static final float TOP_SECTION
private static final float MARGIN
private Rectangle rect
private Rectangle pageRect
private PdfTemplate[] app
private PdfTemplate frm
private PdfStamperImp writer
private String layer2Text
private String reason
private String location
private Calendar signDate
private String provider
private int page
private String fieldName
private PrivateKey privKey
private Certificate[] certChain
private CRL[] crlList
private PdfName filter
private boolean newField
private ByteBuffer sigout
private OutputStream originalout
private File tempFile
private PdfDictionary cryptoDictionary
private PdfStamper stamper
private boolean preClosed
private PdfSigGenericPKCS sigStandard
private int[] range
private RandomAccessFile raf
private byte[] bout
private int boutLen
private byte[] externalDigest
private byte[] externalRSAdata
private String digestEncryptionAlgorithm
private HashMap exclusionLocations
private int render
private Image signatureGraphic
public static final String questionMark
private String contact
private Font layer2Font
private String layer4Text
private boolean acro6Layers
private int runDirection
private PdfSignatureAppearance.SignatureEvent signatureEvent
private Image image
private float imageScale
private int certificationLevel
Constructor Detail |
---|
PdfSignatureAppearance(PdfStamperImp writer)
Method Detail |
---|
public int getRender()
public void setRender(int render)
SignatureRenderDescription
,
SignatureRenderNameAndDescription
or SignatureRenderGraphicAndDescription
.
The two last modes should be used with Acrobat 6 layer type.
render
- the render modepublic Image getSignatureGraphic()
public void setSignatureGraphic(Image signatureGraphic)
SignatureRenderGraphicAndDescription
signatureGraphic
- image rendered. If null
the mode is defaulted
to SignatureRenderDescription
public void setLayer2Text(String text)
text
- the signature text identifying the signer. If null
or not set
a standard description will be usedpublic String getLayer2Text()
public void setLayer4Text(String text)
text
- the text identifying the signature status. If null
or not set
the description "Signature Not Verified" will be usedpublic String getLayer4Text()
public Rectangle getRect()
null
or have zero width or height for invisible signaturespublic boolean isInvisible()
public void setCrypto(PrivateKey privKey, Certificate[] certChain, CRL[] crlList, PdfName filter)
privKey
- the private keycertChain
- the certificate chaincrlList
- the certificate revocation list. It may be null
filter
- the crytographic filter type. It can be SELF_SIGNED, VERISIGN_SIGNED or WINCER_SIGNEDpublic void setVisibleSignature(Rectangle pageRect, int page, String fieldName)
pageRect
- the position and dimension of the field in the pagepage
- the page to place the field. The fist page is 1fieldName
- the field name or null
to generate automatically a new field namepublic void setVisibleSignature(String fieldName)
fieldName
- the existing empty signature field namepublic PdfTemplate getLayer(int layer)
Consult PPKAppearances.pdf for further details.
layer
- the layer
public PdfTemplate getTopLayer()
Consult PPKAppearances.pdf for further details.
public PdfTemplate getAppearance() throws DocumentException
Consult PPKAppearances.pdf for further details.
DocumentException
- on errorpublic static float fitText(Font font, String text, Rectangle rect, float maxFontSize, int runDirection)
font
- the font to usetext
- the textrect
- the rectangle where the text must fitmaxFontSize
- the maximum font sizerunDirection
- the run direction
public void setExternalDigest(byte[] digest, byte[] RSAdata, String digestEncryptionAlgorithm)
digest
- the digest. This is the actual signatureRSAdata
- the extra data that goes into the data tag in PKCS#7digestEncryptionAlgorithm
- the encryption algorithm. It may must be null
if the digest
is also null
. If the digest
is not null
then it may be "RSA" or "DSA"public String getReason()
public void setReason(String reason)
reason
- the signing reasonpublic String getLocation()
public void setLocation(String location)
location
- the signing locationpublic String getProvider()
null
to use the default provider.public void setProvider(String provider)
provider
- the name of the provider, for example "SUN", or
null
to use the default provider.public PrivateKey getPrivKey()
public Certificate[] getCertChain()
public CRL[] getCrlList()
public PdfName getFilter()
public boolean isNewField()
true
if a new field was created, false
if signing
an existing field or if the signature is invisiblepublic int getPage()
public String getFieldName()
public Rectangle getPageRect()
public Calendar getSignDate()
public void setSignDate(Calendar signDate)
signDate
- the signature dateByteBuffer getSigout()
void setSigout(ByteBuffer sigout)
OutputStream getOriginalout()
void setOriginalout(OutputStream originalout)
public File getTempFile()
null
is the document is created in memoryvoid setTempFile(File tempFile)
public String getNewSigName()
public void preClose() throws IOException, DocumentException
If calling preClose() dont't call PdfStamper.close().
No external signatures are allowed if this method is called.
IOException
- on error
DocumentException
- on errorpublic void preClose(HashMap exclusionSizes) throws IOException, DocumentException
If calling preClose() dont't call PdfStamper.close().
If using an external signature exclusionSizes
must contain at least
the PdfName.CONTENTS
key with the size that it will take in the
document. Note that due to the hex string coding this size should be
byte_size*2+2.
exclusionSizes
- a HashMap
with names and sizes to be excluded in the signature
calculation. The key is a PdfName
and the value an
Integer
. At least the PdfName.CONTENTS
must be present
IOException
- on error
DocumentException
- on errorpublic void close(PdfDictionary update) throws IOException, DocumentException
update
is a PdfDictionary
that must have exactly the
same keys as the ones provided in preClose(HashMap)
.
update
- a PdfDictionary
with the key/value that will fill the holes defined
in preClose(HashMap)
DocumentException
- on error
IOException
- on errorprivate void addDocMDP(PdfDictionary crypto)
public InputStream getRangeStream()
public PdfDictionary getCryptoDictionary()
public void setCryptoDictionary(PdfDictionary cryptoDictionary)
cryptoDictionary
- a user made signature dictionarypublic PdfStamper getStamper()
PdfStamper
associated with this instance.
PdfStamper
associated with this instancevoid setStamper(PdfStamper stamper)
public boolean isPreClosed()
true
if the document is in the process of closing,
false
otherwisepublic PdfSigGenericPKCS getSigStandard()
The main use is to insert external signatures.
public String getContact()
public void setContact(String contact)
contact
- the signing contactpublic Font getLayer2Font()
public void setLayer2Font(Font layer2Font)
layer2Font
- the n2 and n4 fontpublic boolean isAcro6Layers()
public void setAcro6Layers(boolean acro6Layers)
acro6Layers
- if true
only the layers n2 and n4 will be presentpublic void setRunDirection(int runDirection)
runDirection
- the run directionpublic int getRunDirection()
public PdfSignatureAppearance.SignatureEvent getSignatureEvent()
public void setSignatureEvent(PdfSignatureAppearance.SignatureEvent signatureEvent)
signatureEvent
- the signature eventpublic Image getImage()
public void setImage(Image image)
image
- the background image for the layer 2public float getImageScale()
public void setImageScale(float imageScale)
imageScale
- the scaling to be applied to the background imagepublic int getCertificationLevel()
public void setCertificationLevel(int certificationLevel)
certificationLevel
- the values can be: NOT_CERTIFIED
, CERTIFIED_NO_CHANGES_ALLOWED
,
CERTIFIED_FORM_FILLING
and CERTIFIED_FORM_FILLING_AND_ANNOTATIONS
|
Hosted by Hostbasket | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |