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 newPdfSignature
instance from the providedPdfDictionary
.PdfSignature(PdfName filter, PdfName subFilter)
Creates new PdfSignature.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PdfArray
getByteRange()
Gets the /ByteRange.PdfString
getCert()
Gets the /Cert entry value of this signature.PdfObject
getCertObject()
Gets the /Cert entry value of this signature.PdfString
getContents()
Gets the /Contents entry value.PdfString
getDate()
Gets the /M value.java.lang.String
getLocation()
Gets the /Location entry value.java.lang.String
getName()
gets the /Name of the person signing the document.private PdfSignatureBuildProperties
getPdfSignatureBuildProperties()
Gets thePdfSignatureBuildProperties
instance if it exists, if not it adds a new one and returns this.java.lang.String
getReason()
Gets the /Reason value.PdfName
getSubFilter()
A name that describes the encoding of the signature value and key information in the signature dictionary.PdfName
getType()
The type of PDF object that the wrapped dictionary describes; if present, shall bePdfName.Sig
for a signature dictionary orPdfName.DocTimeStamp
for a timestamp signature dictionary.protected boolean
isWrappedObjectMustBeIndirect()
Defines if the object behind this wrapper must be an indirect object in the resultant document.PdfSignature
put(PdfName key, PdfObject value)
Add new key-value pair to the signature dictionary.void
setByteRange(int[] range)
Sets the /ByteRange.void
setCert(byte[] cert)
Sets the /Cert value of this signature.void
setContact(java.lang.String contactInfo)
Sets the /ContactInfo value.void
setContents(byte[] contents)
Sets the /Contents value to the specified byte[].void
setDate(PdfDate date)
Sets the /M value.void
setLocation(java.lang.String location)
Sets the /Location value.void
setName(java.lang.String name)
Sets the /Name of the person signing the document.void
setReason(java.lang.String reason)
Sets the /Reason value.void
setSignatureCreator(java.lang.String signatureCreator)
Sets the signature creator name in thePdfSignatureBuildProperties
dictionary.-
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 newPdfSignature
instance from the providedPdfDictionary
.- Parameters:
sigDictionary
-PdfDictionary
to create newPdfSignature
instance 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
PdfName
which usually has a value eitherPdfName.Adbe_pkcs7_detached
orPdfName.ETSI_CAdES_DETACHED
.
-
getType
public PdfName getType()
The type of PDF object that the wrapped dictionary describes; if present, shall bePdfName.Sig
for a signature dictionary orPdfName.DocTimeStamp
for a timestamp signature dictionary. Shall be not null if it's value isPdfName.DocTimeStamp
. The default value is:PdfName.Sig
.- Returns:
- a
PdfName
that 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:
PdfString
which 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 thePdfSignatureBuildProperties
dictionary.- 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
-PdfName
to be added as a keyvalue
-PdfObject
to be added as a value- Returns:
- the same
PdfSignature
instance
-
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:
isWrappedObjectMustBeIndirect
in classPdfObjectWrapper<PdfDictionary>
- Returns:
- true if in the resultant document the object behind the wrapper must be indirect, otherwise false.
-
getPdfSignatureBuildProperties
private PdfSignatureBuildProperties getPdfSignatureBuildProperties()
Gets thePdfSignatureBuildProperties
instance if it exists, if not it adds a new one and returns this.- Returns:
PdfSignatureBuildProperties
-
-