Package com.itextpdf.signatures
Class PdfSignature
- java.lang.Object
-
- com.itextpdf.kernel.pdf.PdfObjectWrapper<PdfDictionary>
-
- com.itextpdf.signatures.PdfSignature
-
public class PdfSignature extends PdfObjectWrapper<PdfDictionary>
Represents the signature dictionary.
-
-
Constructor Summary
Constructors Constructor Description PdfSignature()Creates new PdfSignature.PdfSignature(PdfDictionary sigDictionary)Creates newPdfSignatureinstance from the providedPdfDictionary.PdfSignature(PdfName filter, PdfName subFilter)Creates new PdfSignature.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PdfArraygetByteRange()Gets the /ByteRange.PdfStringgetCert()Gets the /Cert entry value of this signature.PdfObjectgetCertObject()Gets the /Cert entry value of this signature.PdfStringgetContents()Gets the /Contents entry value.PdfStringgetDate()Gets the /M value.java.lang.StringgetLocation()Gets the /Location entry value.java.lang.StringgetName()gets the /Name of the person signing the document.private PdfSignatureBuildPropertiesgetPdfSignatureBuildProperties()Gets thePdfSignatureBuildPropertiesinstance if it exists, if not it adds a new one and returns this.java.lang.StringgetReason()Gets the /Reason value.PdfNamegetSubFilter()A name that describes the encoding of the signature value and key information in the signature dictionary.PdfNamegetType()The type of PDF object that the wrapped dictionary describes; if present, shall bePdfName.Sigfor a signature dictionary orPdfName.DocTimeStampfor a timestamp signature dictionary.protected booleanisWrappedObjectMustBeIndirect()Defines if the object behind this wrapper must be an indirect object in the resultant document.PdfSignatureput(PdfName key, PdfObject value)Add new key-value pair to the signature dictionary.voidsetByteRange(int[] range)Sets the /ByteRange.voidsetCert(byte[] cert)Sets the /Cert value of this signature.voidsetContact(java.lang.String contactInfo)Sets the /ContactInfo value.voidsetContents(byte[] contents)Sets the /Contents value to the specified byte[].voidsetDate(PdfDate date)Sets the /M value.voidsetLocation(java.lang.String location)Sets the /Location value.voidsetName(java.lang.String name)Sets the /Name of the person signing the document.voidsetReason(java.lang.String reason)Sets the /Reason value.voidsetSignatureCreator(java.lang.String signatureCreator)Sets the signature creator name in thePdfSignatureBuildPropertiesdictionary.-
Methods inherited from class com.itextpdf.kernel.pdf.PdfObjectWrapper
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
-
-
-
-
Constructor Detail
-
PdfSignature
public PdfSignature()
Creates new PdfSignature.
-
PdfSignature
public PdfSignature(PdfName filter, PdfName subFilter)
Creates new PdfSignature.- Parameters:
filter- PdfName of the signature handler to use when validating this signaturesubFilter- PdfName that describes the encoding of the signature
-
PdfSignature
public PdfSignature(PdfDictionary sigDictionary)
Creates newPdfSignatureinstance from the providedPdfDictionary.- Parameters:
sigDictionary-PdfDictionaryto create newPdfSignatureinstance from
-
-
Method Detail
-
getSubFilter
public PdfName getSubFilter()
A name that describes the encoding of the signature value and key information in the signature dictionary.- Returns:
- a
PdfNamewhich usually has a value eitherPdfName.Adbe_pkcs7_detachedorPdfName.ETSI_CAdES_DETACHED.
-
getType
public PdfName getType()
The type of PDF object that the wrapped dictionary describes; if present, shall bePdfName.Sigfor a signature dictionary orPdfName.DocTimeStampfor a timestamp signature dictionary. Shall be not null if it's value isPdfName.DocTimeStamp. The default value is:PdfName.Sig.- Returns:
- a
PdfNamethat identifies type of the wrapped dictionary, returns null if it is not explicitly specified.
-
setByteRange
public void setByteRange(int[] range)
Sets the /ByteRange.- Parameters:
range- an array of pairs of integers that specifies the byte range used in the digest calculation. A pair consists of the starting byte offset and the length
-
getByteRange
public PdfArray getByteRange()
Gets the /ByteRange.- Returns:
- an array of pairs of integers that specifies the byte range used in the digest calculation. A pair consists of the starting byte offset and the length.
-
setContents
public void setContents(byte[] contents)
Sets the /Contents value to the specified byte[].- Parameters:
contents- a byte[] representing the digest
-
getContents
public PdfString getContents()
Gets the /Contents entry value. See ISO 32000-1 12.8.1, Table 252 – Entries in a signature dictionary.- Returns:
- the signature content
-
setCert
public void setCert(byte[] cert)
Sets the /Cert value of this signature.- Parameters:
cert- the byte[] representing the certificate chain
-
getCert
public PdfString getCert()
Gets the /Cert entry value of this signature. See ISO 32000-1 12.8.1, Table 252 – Entries in a signature dictionary.- Returns:
- the signature cert
-
getCertObject
public PdfObject getCertObject()
Gets the /Cert entry value of this signature. /Cert entry required when SubFilter is adbe.x509.rsa_sha1. May be array or byte string.- Returns:
- the signature cert value
-
setName
public void setName(java.lang.String name)
Sets the /Name of the person signing the document.- Parameters:
name- name of the person signing the document
-
getName
public java.lang.String getName()
gets the /Name of the person signing the document.- Returns:
- name of the person signing the document.
-
setDate
public void setDate(PdfDate date)
Sets the /M value. Should only be used if the time of signing is not available in the signature.- Parameters:
date- time of signing
-
getDate
public PdfString getDate()
Gets the /M value. Should only be used if the time of signing is not available in the signature.- Returns:
PdfStringwhich denotes time of signing.
-
setLocation
public void setLocation(java.lang.String location)
Sets the /Location value.- Parameters:
location- physical location of signing
-
getLocation
public java.lang.String getLocation()
Gets the /Location entry value.- Returns:
- physical location of signing.
-
setReason
public void setReason(java.lang.String reason)
Sets the /Reason value.- Parameters:
reason- reason for signing
-
getReason
public java.lang.String getReason()
Gets the /Reason value.- Returns:
- reason for signing
-
setSignatureCreator
public void setSignatureCreator(java.lang.String signatureCreator)
Sets the signature creator name in thePdfSignatureBuildPropertiesdictionary.- Parameters:
signatureCreator- name of the signature creator
-
setContact
public void setContact(java.lang.String contactInfo)
Sets the /ContactInfo value.- Parameters:
contactInfo- information to contact the person who signed this document
-
put
public PdfSignature put(PdfName key, PdfObject value)
Add new key-value pair to the signature dictionary.- Parameters:
key-PdfNameto be added as a keyvalue-PdfObjectto be added as a value- Returns:
- the same
PdfSignatureinstance
-
isWrappedObjectMustBeIndirect
protected boolean isWrappedObjectMustBeIndirect()
Defines if the object behind this wrapper must be an indirect object in the resultant document.
If this method returns true it doesn't necessarily mean that object must be in the indirect state at any moment, but rather defines that when the object will be written to the document it will be transformed into indirect object if it's not indirect yet.
Return value of this method shouldn't depend on any logic, it should return always true or false.- Specified by:
isWrappedObjectMustBeIndirectin classPdfObjectWrapper<PdfDictionary>- Returns:
- true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
-
getPdfSignatureBuildProperties
private PdfSignatureBuildProperties getPdfSignatureBuildProperties()
Gets thePdfSignatureBuildPropertiesinstance if it exists, if not it adds a new one and returns this.- Returns:
PdfSignatureBuildProperties
-
-