Class PdfSignatureAppearance
java.lang.Object
com.gitlab.pdftk_java.com.lowagie.text.pdf.PdfSignatureAppearance
This class takes care of the cryptographic options and appearances that form a signature.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classstatic interfaceAn interface to retrieve the signature dictionary for modification. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanHolds value of property acro6Layers.private PdfTemplate[]private byte[]private intprivate Certificate[]private StringHolds value of property contact.private CRL[]private PdfDictionaryprivate Stringprivate HashMapprivate byte[]private byte[]private Stringprivate PdfNameprivate PdfTemplateprivate floatHolds value of property imageScale.private FontHolds value of property layer2Font.private Stringprivate StringHolds value of property layer4Text.private Stringprivate static final floatprivate booleanprivate OutputStreamprivate intprivate Rectangleprivate booleanprivate PrivateKeyprivate Stringstatic final StringCommands to draw a yellow question mark in a stream contentprivate RandomAccessFileprivate int[]private Stringprivate Rectangleprivate intHolds value of property runDirection.static final PdfNameThe self signed filter.Holds value of property signatureEvent.private Calendarprivate ByteBufferprivate PdfSigGenericPKCSprivate PdfStamperprivate Fileprivate static final floatstatic final PdfNameThe VeriSign filter.static final PdfNameThe Windows Certificate Security.private PdfStamperImp -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose(PdfDictionary update) This is the last method to be called when using external signatures.static floatFits the text to some rectangle adjusting the font size as needed.Gets the main appearance layer.Gets the certificate chain.Gets the signing contact.CRL[]Gets the certificate revocation list.Gets the user made signature dictionary.Gets the field name.Gets the filter used to sign the document.floatGets the scaling to be applied to the background image.getLayer(int layer) Gets a template layer to create a signature appearance.Gets the n2 and n4 layer font.Gets the signature text identifying the signer if set by setLayer2Text().Gets the text identifying the signature status if set by setLayer4Text().Gets the signing location.Gets a new signature fied name that doesn't clash with any existing name.(package private) OutputStreamintgetPage()Gets the page number of the field.Gets the rectangle that represent the position and dimension of the signature in the page.Gets the private key.Returns the Cryptographic Service Provider that will sign the document.Gets the document bytes that are hashable when using external signatures.Gets the signing reason.getRect()Gets the rectangle representing the signature dimensions.intGets the run direction.Getter for property signatureEvent.Gets the signature date.(package private) ByteBufferGets the instance of the standard signature dictionary.Gets thePdfStamperassociated with this instance.Gets the temporary file.Gets the template that aggregates all appearance layers.booleanGets the Acrobat 6.0 layer mode.booleanGets the visibility status of the signature.booleanChecks if a new field was created.booleanChecks if the document is in the process of closing.voidpreClose()This is the first method to be called when using external signatures.voidThis is the first method to be called when using external signatures.voidsetAcro6Layers(boolean acro6Layers) Acrobat 6.0 and higher recomends that only layer n2 and n4 be present.voidsetContact(String contact) Sets the signing contact.voidsetCrypto(PrivateKey privKey, Certificate[] certChain, CRL[] crlList, PdfName filter) Sets the cryptographic parameters.voidsetCryptoDictionary(PdfDictionary cryptoDictionary) Sets a user made signature dictionary.voidsetExternalDigest(byte[] digest, byte[] RSAdata, String digestEncryptionAlgorithm) Sets the digest/signature to an external calculated value.voidsetImageScale(float imageScale) Sets the scaling to be applied to the background image.voidsetLayer2Font(Font layer2Font) Sets the n2 and n4 layer font.voidsetLayer2Text(String text) Sets the signature text identifying the signer.voidsetLayer4Text(String text) Sets the text identifying the signature status.voidsetLocation(String location) Sets the signing location.(package private) voidsetOriginalout(OutputStream originalout) voidsetProvider(String provider) Sets the Cryptographic Service Provider that will sign the document.voidSets the signing reason.voidsetRunDirection(int runDirection) Sets the run direction in the n2 and n4 layer.voidsetSignatureEvent(PdfSignatureAppearance.SignatureEvent signatureEvent) Sets the signature event to allow modification of the signature dictionary.voidsetSignDate(Calendar signDate) Sets the signature date.(package private) voidsetSigout(ByteBuffer sigout) (package private) voidsetStamper(PdfStamper stamper) (package private) voidsetTempFile(File tempFile) voidsetVisibleSignature(Rectangle pageRect, int page, String fieldName) Sets the signature to be visible.voidsetVisibleSignature(String fieldName) Sets the signature to be visible.
-
Field Details
-
SELF_SIGNED
The self signed filter. -
VERISIGN_SIGNED
The VeriSign filter. -
WINCER_SIGNED
The Windows Certificate Security. -
topSection
private static final float topSection- See Also:
-
margin
private static final float margin- See Also:
-
rect
-
pageRect
-
app
-
frm
-
writer
-
layer2Text
-
reason
-
location
-
signDate
-
provider
-
page
private int page -
fieldName
-
privKey
-
certChain
-
crlList
-
filter
-
newField
private boolean newField -
sigout
-
originalout
-
tempFile
-
cryptoDictionary
-
stamper
-
preClosed
private boolean preClosed -
sigStandard
-
range
private int[] range -
raf
-
bout
private byte[] bout -
boutLen
private int boutLen -
externalDigest
private byte[] externalDigest -
externalRSAdata
private byte[] externalRSAdata -
digestEncryptionAlgorithm
-
exclusionLocations
-
questionMark
Commands to draw a yellow question mark in a stream content- See Also:
-
contact
Holds value of property contact. -
layer2Font
Holds value of property layer2Font. -
layer4Text
Holds value of property layer4Text. -
acro6Layers
private boolean acro6LayersHolds value of property acro6Layers. -
runDirection
private int runDirectionHolds value of property runDirection. -
signatureEvent
Holds value of property signatureEvent. -
imageScale
private float imageScaleHolds value of property imageScale.
-
-
Constructor Details
-
PdfSignatureAppearance
PdfSignatureAppearance(PdfStamperImp writer)
-
-
Method Details
-
setLayer2Text
Sets the signature text identifying the signer.- Parameters:
text- the signature text identifying the signer. Ifnullor not set a standard description will be used
-
getLayer2Text
Gets the signature text identifying the signer if set by setLayer2Text().- Returns:
- the signature text identifying the signer
-
setLayer4Text
Sets the text identifying the signature status.- Parameters:
text- the text identifying the signature status. Ifnullor not set the description "Signature Not Verified" will be used
-
getLayer4Text
Gets the text identifying the signature status if set by setLayer4Text().- Returns:
- the text identifying the signature status
-
getRect
Gets the rectangle representing the signature dimensions.- Returns:
- the rectangle representing the signature dimensions. It may be
nullor have zero width or height for invisible signatures
-
isInvisible
public boolean isInvisible()Gets the visibility status of the signature.- Returns:
- the visibility status of the signature
-
setCrypto
Sets the cryptographic parameters.- Parameters:
privKey- the private keycertChain- the certificate chaincrlList- the certificate revocation list. It may benullfilter- the crytographic filter type. It can be SELF_SIGNED, VERISIGN_SIGNED or WINCER_SIGNED
-
setVisibleSignature
Sets the signature to be visible. It creates a new visible signature field.- Parameters:
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 ornullto generate automatically a new field name
-
setVisibleSignature
Sets the signature to be visible. An empty signature field with the same name must already exist.- Parameters:
fieldName- the existing empty signature field name
-
getLayer
Gets a template layer to create a signature appearance. The layers can go from 0 to 4.Consult PPKAppearances.pdf for further details.
- Parameters:
layer- the layer- Returns:
- a template
-
getTopLayer
Gets the template that aggregates all appearance layers. This corresponds to the /FRM resource.Consult PPKAppearances.pdf for further details.
- Returns:
- the template that aggregates all appearance layers
-
getAppearance
Gets the main appearance layer.Consult PPKAppearances.pdf for further details.
- Returns:
- the main appearance layer
- Throws:
DocumentException- on errorIOException- on error
-
fitText
public 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.- Parameters:
font- the font to usetext- the textrect- the rectangle where the text must fitmaxFontSize- the maximum font sizerunDirection- the run direction- Returns:
- the calculated font size that makes the text fit
-
setExternalDigest
Sets the digest/signature to an external calculated value.- Parameters:
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 benullif thedigestis alsonull. If thedigestis notnullthen it may be "RSA" or "DSA"
-
getReason
-
setReason
Sets the signing reason.- Parameters:
reason- the signing reason
-
getLocation
-
setLocation
Sets the signing location.- Parameters:
location- the signing location
-
getProvider
Returns the Cryptographic Service Provider that will sign the document.- Returns:
- provider the name of the provider, for example "SUN",
or
nullto use the default provider.
-
setProvider
Sets the Cryptographic Service Provider that will sign the document.- Parameters:
provider- the name of the provider, for example "SUN", ornullto use the default provider.
-
getPrivKey
-
getCertChain
-
getCrlList
Gets the certificate revocation list.- Returns:
- the certificate revocation list
-
getFilter
Gets the filter used to sign the document.- Returns:
- the filter used to sign the document
-
isNewField
public boolean isNewField()Checks if a new field was created.- Returns:
trueif a new field was created,falseif signing an existing field or if the signature is invisible
-
getPage
public int getPage()Gets the page number of the field.- Returns:
- the page number of the field
-
getFieldName
-
getPageRect
Gets the rectangle that represent the position and dimension of the signature in the page.- Returns:
- the rectangle that represent the position and dimension of the signature in the page
-
getSignDate
-
setSignDate
Sets the signature date.- Parameters:
signDate- the signature date
-
getSigout
ByteBuffer getSigout() -
setSigout
-
getOriginalout
OutputStream getOriginalout() -
setOriginalout
-
getTempFile
Gets the temporary file.- Returns:
- the temporary file or
nullis the document is created in memory
-
setTempFile
-
getNewSigName
Gets a new signature fied name that doesn't clash with any existing name.- Returns:
- a new signature fied name
-
preClose
This is the first method to be called when using external signatures. The general sequence is: preClose(), getDocumentBytes() and close().If calling preClose() dont't call PdfStamper.close().
No external signatures are allowed if this methos is called.
- Throws:
IOException- on errorDocumentException- on error
-
preClose
This is the first method to be called when using external signatures. The general sequence is: preClose(), getDocumentBytes() and close().If calling preClose() dont't call PdfStamper.close().
If using an external signature
exclusionSizesmust contain at least thePdfName.CONTENTSkey 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.- Parameters:
exclusionSizes- aHashMapwith names and sizes to be excluded in the signature calculation. The key is aPdfNameand the value anInteger. At least thePdfName.CONTENTSmust be present- Throws:
IOException- on errorDocumentException- on error
-
close
This is the last method to be called when using external signatures. The general sequence is: preClose(), getDocumentBytes() and close().updateis aPdfDictionarythat must have exactly the same keys as the ones provided inpreClose(HashMap).- Parameters:
update- aPdfDictionarywith the key/value that will fill the holes defined inpreClose(HashMap)- Throws:
DocumentException- on errorIOException- on error
-
getRangeStream
Gets the document bytes that are hashable when using external signatures. The general sequence is: preClose(), getRangeStream() and close().- Returns:
- the document bytes that are hashable
-
getCryptoDictionary
Gets the user made signature dictionary. This is the dictionary at the /V key.- Returns:
- the user made signature dictionary
-
setCryptoDictionary
Sets a user made signature dictionary. This is the dictionary at the /V key.- Parameters:
cryptoDictionary- a user made signature dictionary
-
getStamper
Gets thePdfStamperassociated with this instance.- Returns:
- the
PdfStamperassociated with this instance
-
setStamper
-
isPreClosed
public boolean isPreClosed()Checks if the document is in the process of closing.- Returns:
trueif the document is in the process of closing,falseotherwise
-
getSigStandard
Gets the instance of the standard signature dictionary. This instance is only available after pre close.The main use is to insert external signatures.
- Returns:
- the instance of the standard signature dictionary
-
getContact
-
setContact
Sets the signing contact.- Parameters:
contact- the signing contact
-
getLayer2Font
-
setLayer2Font
Sets the n2 and n4 layer font. If the font size is zero, auto-fit will be used.- Parameters:
layer2Font- the n2 and n4 font
-
isAcro6Layers
public boolean isAcro6Layers()Gets the Acrobat 6.0 layer mode.- Returns:
- the Acrobat 6.0 layer mode
-
setAcro6Layers
public void setAcro6Layers(boolean acro6Layers) Acrobat 6.0 and higher recomends that only layer n2 and n4 be present. This method sets that mode.- Parameters:
acro6Layers- iftrueonly the layers n2 and n4 will be present
-
setRunDirection
public void setRunDirection(int runDirection) Sets the run direction in the n2 and n4 layer.- Parameters:
runDirection- the run direction
-
getRunDirection
public int getRunDirection()Gets the run direction.- Returns:
- the run direction
-
getSignatureEvent
Getter for property signatureEvent.- Returns:
- Value of property signatureEvent.
-
setSignatureEvent
Sets the signature event to allow modification of the signature dictionary.- Parameters:
signatureEvent- the signature event
-
getImageScale
public float getImageScale()Gets the scaling to be applied to the background image.- Returns:
- the scaling to be applied to the background image
-
setImageScale
public void setImageScale(float imageScale) Sets the scaling to be applied to the background image. If it's zero the image will fully fill the rectangle. If it's less than zero the image will fill the rectangle but will keep the proportions. If it's greater than zero that scaling will be applied. In any of the cases the image will always be centered. It's zero by default.- Parameters:
imageScale- the scaling to be applied to the background image
-