Class PdfSigner
- java.lang.Object
-
- com.itextpdf.signatures.PdfSigner
-
public class PdfSigner extends java.lang.ObjectTakes care of the cryptographic options and appearances that form a signature.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPdfSigner.CryptoStandardEnum containing the Cryptographic Standards.(package private) static interfacePdfSigner.ISignatureDataProviderstatic interfacePdfSigner.ISignatureEventAn interface to retrieve the signature dictionary for modification.private static classPdfSigner.PdfSignerDocument(package private) static classPdfSigner.SignatureApplier
-
Field Summary
Fields Modifier and Type Field Description private PdfAcroFormacroFormAcroForm for the PdfDocument.protected byte[]boutThe bytes of the file right before the signature is added (if raf is null).protected booleanclosedBoolean to check if this PdfSigner instance has been closed already or not.protected PdfSignaturecryptoDictionaryThe crypto dictionary.protected PdfDocumentdocumentThe PdfDocument.protected java.util.Map<PdfName,PdfLiteral>exclusionLocationsName and content of keys that can only be added in the close() method.private static IBouncyCastleFactoryFACTORYprivate static java.lang.StringID_ATTR_PDF_MAC_DATA(package private) static intMAXIMUM_MAC_SIZEprotected java.io.OutputStreamoriginalOSOutputStream for the bytes of the document.protected booleanpreClosedIndicates if the pdf document has already been pre-closed.protected java.io.RandomAccessFilerafThe file right before the signature is added (can be null).protected long[]rangeArray containing the byte positions of the bytes that need to be hashed.protected PdfSigner.ISignatureEventsignatureEventHolds value of property signatureEvent.private java.lang.StringsignerNameThe name of the signer extracted from the signing certificate.private SignerPropertiessignerPropertiesProperties to be used in signing operations.protected java.io.FiletempFileTempfile to hold the output temporarily.protected java.io.ByteArrayOutputStreamtemporaryOSOutputstream that temporarily holds the output in memory.
-
Constructor Summary
Constructors Constructor Description PdfSigner(PdfDocument document, java.io.OutputStream outputStream, java.io.ByteArrayOutputStream temporaryOS, java.io.File tempFile)PdfSigner(PdfReader reader, java.io.OutputStream outputStream, StampingProperties properties)Creates a PdfSigner instance.PdfSigner(PdfReader reader, java.io.OutputStream outputStream, java.lang.String path, StampingProperties properties)Creates a PdfSigner instance.PdfSigner(PdfReader reader, java.io.OutputStream outputStream, java.lang.String path, StampingProperties stampingProperties, SignerProperties signerProperties)Creates a PdfSigner instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidaddDeveloperExtension(PdfDeveloperExtension extension)Add developer extension to the currentPdfDocument.protected voidaddDocMDP(PdfSignature crypto)Adds keys to the signature dictionary that define the certification level and the permissions.protected voidaddFieldMDP(PdfSignature crypto, PdfSigFieldLock fieldLock)Adds keys to the signature dictionary that define the field permissions.protected voidapplyAccessibilityProperties(PdfFormField formField, IAccessibleElement modelElement, PdfDocument pdfDocument)AppliesAccessibilityPropertiesfor provided signature field.private voidapplyDefaultPropertiesForTheNewField(PdfSignatureFormField sigField)protected voidclose(PdfDictionary update)This is the last method to be called when using external signatures.protected PdfSigFieldLockcreateNewSignatureFormField(PdfAcroForm acroForm, java.lang.String name)Creates new signature form field and adds it to the acroForm object.(package private) PdfSignaturecreateSignatureDictionary(boolean includeDate)protected booleandocumentContainsCertificationOrApprovalSignatures()Check if current document instance already contains certification or approval signatures.(package private) byte[]embedMacTokenIntoSignatureContainer(byte[] signatureContainer)(package private) static byte[]embedMacTokenIntoSignatureContainer(byte[] signatureContainer, java.io.InputStream rangeStream, PdfDocument document)private voidfillInAppearanceText(SignedAppearanceText appearanceText)private SignedAppearanceTextgenerateSignatureText()PdfDocumentgetDocument()Gets the PdfDocument associated with this instance.private java.lang.StringgetFieldName()java.lang.StringgetNewSigFieldName()Gets a new signature field name that doesn't clash with any existing name.protected java.io.InputStreamgetRangeStream()Gets the document bytes that are hashable when using external signatures.protected SignatureFieldAppearancegetSignatureAppearance()Returns final signature appearance object set bySignerProperties.setSignatureAppearance(SignatureFieldAppearance)and customized usingPdfSignerproperties such as signing date, reason, location and signer name in case they weren't specified by the user, or, if none was set, returns a new one with default appearance.PdfSignaturegetSignatureDictionary()Returns the user made signature dictionary.PdfSigner.ISignatureEventgetSignatureEvent()Getter for property signatureEvent.PdfSignatureFormFieldgetSignatureField()Gets the signature field to be signed.private static java.lang.StringgetSignerName(java.security.cert.X509Certificate certificate)SignerPropertiesgetSignerProperties()Gets the properties to be used in signing operations.protected IRandomAccessSourcegetUnderlyingSource()Returns the underlying source.protected intgetWidgetPageNumber(PdfWidgetAnnotation widget)Get the page number associated to the provided widget.protected RectanglegetWidgetRectangle(PdfWidgetAnnotation widget)Get the rectangle associated to the provided widget.protected PdfDocumentinitDocument(PdfReader reader, PdfWriter writer, StampingProperties properties)Initialize newPdfDocumentinstance by using provided parameters.private booleanisDocumentPdf2()protected booleanisPreClosed()Checks if the document is in the process of closing.private voidpopulateExistingModelElement()protected PdfSigFieldLockpopulateExistingSignatureFormField(PdfAcroForm acroForm)Populates already existing signature form field in the acroForm object.protected voidpreClose(java.util.Map<PdfName,java.lang.Integer> exclusionSizes)This is the first method to be called when using external signatures.protected java.util.Collection<byte[]>processCrl(java.security.cert.Certificate cert, java.util.Collection<ICrlClient> crlList)Processes a CRL list.private voidsetContent()protected voidsetDocument(PdfDocument document)Sets the PdfDocument.voidsetOriginalOutputStream(java.io.OutputStream originalOS)Setter for the OutputStream.voidsetSignatureEvent(PdfSigner.ISignatureEvent signatureEvent)Sets the signature event to allow modification of the signature dictionary.PdfSignersetSignerProperties(SignerProperties properties)Sets the properties to be used in signing operations.static voidsignDeferred(PdfDocument document, java.lang.String fieldName, java.io.OutputStream outs, IExternalSignatureContainer externalSignatureContainer)Deprecated.signDeferred(PdfReader, String, OutputStream, IExternalSignatureContainer)should be used instead.static voidsignDeferred(PdfReader reader, java.lang.String fieldName, java.io.OutputStream outs, IExternalSignatureContainer externalSignatureContainer)Signs a PDF where space was already reserved.voidsignDetached(IExternalDigest externalDigest, IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype)Signs the document using the detached mode, CMS or CAdES equivalent.voidsignDetached(IExternalDigest externalDigest, IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype, ISignaturePolicyIdentifier signaturePolicy)Signs the document using the detached mode, CMS or CAdES equivalent.voidsignDetached(IExternalDigest externalDigest, IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype, SignaturePolicyInfo signaturePolicy)Signs the document using the detached mode, CMS or CAdES equivalent.voidsignDetached(IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype)Signs the document using the detached mode, CMS or CAdES equivalent.voidsignDetached(IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype, ISignaturePolicyIdentifier signaturePolicy)Signs the document using the detached mode, CMS or CAdES equivalent.voidsignDetached(IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype, SignaturePolicyInfo signaturePolicy)Signs the document using the detached mode, CMS or CAdES equivalent.voidsignExternalContainer(IExternalSignatureContainer externalSignatureContainer, int estimatedSize)Sign the document using an external container, usually a PKCS7.voidtimestamp(ITSAClient tsa, java.lang.String signatureName)Signs a document with a PAdES-LTV Timestamp.private voidupdateFieldName()
-
-
-
Field Detail
-
MAXIMUM_MAC_SIZE
static final int MAXIMUM_MAC_SIZE
- See Also:
- Constant Field Values
-
FACTORY
private static final IBouncyCastleFactory FACTORY
-
ID_ATTR_PDF_MAC_DATA
private static final java.lang.String ID_ATTR_PDF_MAC_DATA
- See Also:
- Constant Field Values
-
raf
protected java.io.RandomAccessFile raf
The file right before the signature is added (can be null).
-
bout
protected byte[] bout
The bytes of the file right before the signature is added (if raf is null).
-
range
protected long[] range
Array containing the byte positions of the bytes that need to be hashed.
-
document
protected PdfDocument document
The PdfDocument.
-
cryptoDictionary
protected PdfSignature cryptoDictionary
The crypto dictionary.
-
signatureEvent
protected PdfSigner.ISignatureEvent signatureEvent
Holds value of property signatureEvent.
-
originalOS
protected java.io.OutputStream originalOS
OutputStream for the bytes of the document.
-
temporaryOS
protected java.io.ByteArrayOutputStream temporaryOS
Outputstream that temporarily holds the output in memory.
-
tempFile
protected java.io.File tempFile
Tempfile to hold the output temporarily.
-
exclusionLocations
protected java.util.Map<PdfName,PdfLiteral> exclusionLocations
Name and content of keys that can only be added in the close() method.
-
preClosed
protected boolean preClosed
Indicates if the pdf document has already been pre-closed.
-
closed
protected boolean closed
Boolean to check if this PdfSigner instance has been closed already or not.
-
acroForm
private final PdfAcroForm acroForm
AcroForm for the PdfDocument.
-
signerName
private java.lang.String signerName
The name of the signer extracted from the signing certificate.
-
signerProperties
private SignerProperties signerProperties
Properties to be used in signing operations.
-
-
Constructor Detail
-
PdfSigner
public PdfSigner(PdfReader reader, java.io.OutputStream outputStream, StampingProperties properties) throws java.io.IOException
Creates a PdfSigner instance. Uses aByteArrayOutputStreaminstead of a temporary file.- Parameters:
reader- PdfReader that reads the PDF fileoutputStream- OutputStream to write the signed PDF fileproperties-StampingPropertiesfor the signing document. Note that encryption will be preserved regardless of what is set in properties.- Throws:
java.io.IOException- if some I/O problem occurs
-
PdfSigner
public PdfSigner(PdfReader reader, java.io.OutputStream outputStream, java.lang.String path, StampingProperties stampingProperties, SignerProperties signerProperties) throws java.io.IOException
Creates a PdfSigner instance. Uses aByteArrayOutputStreaminstead of a temporary file.- Parameters:
reader- PdfReader that reads the PDF fileoutputStream- OutputStream to write the signed PDF filepath- File to which the output is temporarily writtenstampingProperties-StampingPropertiesfor the signing document. Note that encryption will be preserved regardless of what is set in properties.signerProperties-SignerPropertiesbundled properties to be used in signing operations.- Throws:
java.io.IOException- if some I/O problem occurs
-
PdfSigner
public PdfSigner(PdfReader reader, java.io.OutputStream outputStream, java.lang.String path, StampingProperties properties) throws java.io.IOException
Creates a PdfSigner instance. Uses aByteArrayOutputStreaminstead of a temporary file.- Parameters:
reader- PdfReader that reads the PDF fileoutputStream- OutputStream to write the signed PDF filepath- File to which the output is temporarily writtenproperties-StampingPropertiesfor the signing document. Note that encryption will be preserved regardless of what is set in properties.- Throws:
java.io.IOException- if some I/O problem occurs
-
PdfSigner
PdfSigner(PdfDocument document, java.io.OutputStream outputStream, java.io.ByteArrayOutputStream temporaryOS, java.io.File tempFile)
-
-
Method Detail
-
initDocument
protected PdfDocument initDocument(PdfReader reader, PdfWriter writer, StampingProperties properties)
Initialize newPdfDocumentinstance by using provided parameters.- Parameters:
reader-PdfReaderto be used as a reader in the new documentwriter-PdfWriterto be used as a writer in the new documentproperties-StampingPropertiesto be provided in the new document- Returns:
- new
PdfDocumentinstance
-
setSignerProperties
public PdfSigner setSignerProperties(SignerProperties properties)
Sets the properties to be used in signing operations.- Parameters:
properties- the signer properties- Returns:
- this instance to support fluent interface
-
getSignerProperties
public SignerProperties getSignerProperties()
Gets the properties to be used in signing operations.- Returns:
- the signer properties
-
getSignatureDictionary
public PdfSignature getSignatureDictionary()
Returns the user made signature dictionary. This is the dictionary at the /V key of the signature field.- Returns:
- the user made signature dictionary
-
getSignatureEvent
public PdfSigner.ISignatureEvent getSignatureEvent()
Getter for property signatureEvent.- Returns:
- value of property signatureEvent
-
setSignatureEvent
public void setSignatureEvent(PdfSigner.ISignatureEvent signatureEvent)
Sets the signature event to allow modification of the signature dictionary.- Parameters:
signatureEvent- the signature event
-
getNewSigFieldName
public java.lang.String getNewSigFieldName()
Gets a new signature field name that doesn't clash with any existing name.- Returns:
- A new signature field name.
-
getDocument
public PdfDocument getDocument()
Gets the PdfDocument associated with this instance.- Returns:
- the PdfDocument associated with this instance
-
setDocument
protected void setDocument(PdfDocument document)
Sets the PdfDocument.- Parameters:
document- The PdfDocument
-
setOriginalOutputStream
public void setOriginalOutputStream(java.io.OutputStream originalOS)
Setter for the OutputStream.- Parameters:
originalOS- OutputStream for the bytes of the document
-
getSignatureField
public PdfSignatureFormField getSignatureField()
Gets the signature field to be signed. The field can already be presented in the document. If the field is not presented in the document, it will be created.This field instance is expected to be used for setting appearance related properties such as
PdfSignatureFormField.setReuseAppearance(boolean),PdfSignatureFormField.setBackgroundLayer(com.itextpdf.kernel.pdf.xobject.PdfFormXObject)andPdfSignatureFormField.setSignatureAppearanceLayer(com.itextpdf.kernel.pdf.xobject.PdfFormXObject).Note that for the new signature field
SignerProperties.setPageRect(Rectangle)andSignerProperties.setPageNumber(int)should be called before this method.- Returns:
- the
PdfSignatureFormFieldinstance
-
signDetached
public void signDetached(IExternalDigest externalDigest, IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype) throws java.io.IOException, java.security.GeneralSecurityException
Signs the document using the detached mode, CMS or CAdES equivalent.
NOTE: This method closes the underlying pdf document. This means, that current instance of PdfSigner cannot be used after this method call.- Parameters:
externalSignature- the interface providing the actual signingchain- the certificate chaincrlList- the CRL listocspClient- the OCSP clienttsaClient- the Timestamp clientexternalDigest- an implementation that provides the digestestimatedSize- the reserved size for the signature. It will be estimated if 0sigtype- Either Signature.CMS or Signature.CADES- Throws:
java.io.IOException- if some I/O problem occursjava.security.GeneralSecurityException- if some problem during apply security algorithms occurs
-
signDetached
public void signDetached(IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype) throws java.io.IOException, java.security.GeneralSecurityException
Signs the document using the detached mode, CMS or CAdES equivalent.
NOTE: This method closes the underlying pdf document. This means, that current instance of PdfSigner cannot be used after this method call.- Parameters:
externalSignature- the interface providing the actual signingchain- the certificate chaincrlList- the CRL listocspClient- the OCSP clienttsaClient- the Timestamp clientestimatedSize- the reserved size for the signature. It will be estimated if 0sigtype- Either Signature.CMS or Signature.CADES- Throws:
java.io.IOException- if some I/O problem occursjava.security.GeneralSecurityException- if some problem during apply security algorithms occurs
-
signDetached
public void signDetached(IExternalDigest externalDigest, IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype, SignaturePolicyInfo signaturePolicy) throws java.io.IOException, java.security.GeneralSecurityException
Signs the document using the detached mode, CMS or CAdES equivalent.
NOTE: This method closes the underlying pdf document. This means, that current instance of PdfSigner cannot be used after this method call.- Parameters:
externalSignature- the interface providing the actual signingchain- the certificate chaincrlList- the CRL listocspClient- the OCSP clienttsaClient- the Timestamp clientexternalDigest- an implementation that provides the digestestimatedSize- the reserved size for the signature. It will be estimated if 0sigtype- Either Signature.CMS or Signature.CADESsignaturePolicy- the signature policy (for EPES signatures)- Throws:
java.io.IOException- if some I/O problem occursjava.security.GeneralSecurityException- if some problem during apply security algorithms occurs
-
signDetached
public void signDetached(IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype, SignaturePolicyInfo signaturePolicy) throws java.io.IOException, java.security.GeneralSecurityException
Signs the document using the detached mode, CMS or CAdES equivalent.
NOTE: This method closes the underlying pdf document. This means, that current instance of PdfSigner cannot be used after this method call.- Parameters:
externalSignature- the interface providing the actual signingchain- the certificate chaincrlList- the CRL listocspClient- the OCSP clienttsaClient- the Timestamp clientestimatedSize- the reserved size for the signature. It will be estimated if 0sigtype- Either Signature.CMS or Signature.CADESsignaturePolicy- the signature policy (for EPES signatures)- Throws:
java.io.IOException- if some I/O problem occursjava.security.GeneralSecurityException- if some problem during apply security algorithms occurs
-
signDetached
public void signDetached(IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype, ISignaturePolicyIdentifier signaturePolicy) throws java.io.IOException, java.security.GeneralSecurityException
Signs the document using the detached mode, CMS or CAdES equivalent.
NOTE: This method closes the underlying pdf document. This means, that current instance of PdfSigner cannot be used after this method call.- Parameters:
externalSignature- the interface providing the actual signingchain- the certificate chaincrlList- the CRL listocspClient- the OCSP clienttsaClient- the Timestamp clientestimatedSize- the reserved size for the signature. It will be estimated if 0sigtype- Either Signature.CMS or Signature.CADESsignaturePolicy- the signature policy (for EPES signatures)- Throws:
java.io.IOException- if some I/O problem occursjava.security.GeneralSecurityException- if some problem during apply security algorithms occurs
-
signDetached
public void signDetached(IExternalDigest externalDigest, IExternalSignature externalSignature, java.security.cert.Certificate[] chain, java.util.Collection<ICrlClient> crlList, IOcspClient ocspClient, ITSAClient tsaClient, int estimatedSize, PdfSigner.CryptoStandard sigtype, ISignaturePolicyIdentifier signaturePolicy) throws java.io.IOException, java.security.GeneralSecurityException
Signs the document using the detached mode, CMS or CAdES equivalent.
NOTE: This method closes the underlying pdf document. This means, that current instance of PdfSigner cannot be used after this method call.- Parameters:
externalSignature- the interface providing the actual signingchain- the certificate chaincrlList- the CRL listocspClient- the OCSP clienttsaClient- the Timestamp clientexternalDigest- an implementation that provides the digestestimatedSize- the reserved size for the signature. It will be estimated if 0sigtype- Either Signature.CMS or Signature.CADESsignaturePolicy- the signature policy (for EPES signatures)- Throws:
java.io.IOException- if some I/O problem occursjava.security.GeneralSecurityException- if some problem during apply security algorithms occurs
-
signExternalContainer
public void signExternalContainer(IExternalSignatureContainer externalSignatureContainer, int estimatedSize) throws java.security.GeneralSecurityException, java.io.IOException
Sign the document using an external container, usually a PKCS7. The signature is fully composed externally, iText will just put the container inside the document.
NOTE: This method closes the underlying pdf document. This means, that current instance of PdfSigner cannot be used after this method call.- Parameters:
externalSignatureContainer- the interface providing the actual signingestimatedSize- the reserved size for the signature- Throws:
java.security.GeneralSecurityException- if some problem during apply security algorithms occursjava.io.IOException- if some I/O problem occurs
-
timestamp
public void timestamp(ITSAClient tsa, java.lang.String signatureName) throws java.io.IOException, java.security.GeneralSecurityException
Signs a document with a PAdES-LTV Timestamp. The document is closed at the end.
NOTE: This method closes the underlying pdf document. This means, that current instance of PdfSigner cannot be used after this method call.- Parameters:
tsa- the timestamp generatorsignatureName- the signature name or null to have a name generated automatically- Throws:
java.io.IOException- if some I/O problem occurs or estimation for timestamp signature, provided withITSAClient.getTokenSizeEstimate(), is not big enoughjava.security.GeneralSecurityException- if some problem during apply security algorithms occurs
-
signDeferred
@Deprecated public static void signDeferred(PdfDocument document, java.lang.String fieldName, java.io.OutputStream outs, IExternalSignatureContainer externalSignatureContainer) throws java.io.IOException, java.security.GeneralSecurityException
Deprecated.signDeferred(PdfReader, String, OutputStream, IExternalSignatureContainer)should be used instead.Signs a PDF where space was already reserved.- Parameters:
document- the original PDFfieldName- the field to sign. It must be the last fieldouts- the output PDFexternalSignatureContainer- the signature container doing the actual signing. Only the method ExternalSignatureContainer.sign is used- Throws:
java.io.IOException- if some I/O problem occursjava.security.GeneralSecurityException- if some problem during apply security algorithms occurs
-
signDeferred
public static void signDeferred(PdfReader reader, java.lang.String fieldName, java.io.OutputStream outs, IExternalSignatureContainer externalSignatureContainer) throws java.io.IOException, java.security.GeneralSecurityException
Signs a PDF where space was already reserved.- Parameters:
reader-PdfReaderthat reads the PDF filefieldName- the field to sign. It must be the last fieldouts- the output PDFexternalSignatureContainer- the signature container doing the actual signing. Only the method ExternalSignatureContainer.sign is used- Throws:
java.io.IOException- if some I/O problem occursjava.security.GeneralSecurityException- if some problem during apply security algorithms occurs
-
processCrl
protected java.util.Collection<byte[]> processCrl(java.security.cert.Certificate cert, java.util.Collection<ICrlClient> crlList) throws java.security.cert.CertificateEncodingExceptionProcesses a CRL list.- Parameters:
cert- a Certificate if one of the CrlList implementations needs to retrieve the CRL URL from it.crlList- a list of CrlClient implementations- Returns:
- a collection of CRL bytes that can be embedded in a PDF
- Throws:
java.security.cert.CertificateEncodingException- if an encoding error occurs inCertificate.
-
addDeveloperExtension
protected void addDeveloperExtension(PdfDeveloperExtension extension)
Add developer extension to the currentPdfDocument.- Parameters:
extension-PdfDeveloperExtensionto be added
-
isPreClosed
protected boolean isPreClosed()
Checks if the document is in the process of closing.- Returns:
- true if the document is in the process of closing, false otherwise
-
preClose
protected void preClose(java.util.Map<PdfName,java.lang.Integer> exclusionSizes) throws java.io.IOException
This is the first method to be called when using external signatures. The general sequence is: preClose(), getDocumentBytes() and close().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- Map with names and sizes to be excluded in the signature calculation. The key is a PdfName and the value an Integer. At least the /Contents must be present- Throws:
java.io.IOException- on error
-
getSignatureAppearance
protected SignatureFieldAppearance getSignatureAppearance()
Returns final signature appearance object set bySignerProperties.setSignatureAppearance(SignatureFieldAppearance)and customized usingPdfSignerproperties such as signing date, reason, location and signer name in case they weren't specified by the user, or, if none was set, returns a new one with default appearance.To customize the appearance of the signature, create new
SignatureFieldAppearanceobject and set it usingSignerProperties.setSignatureAppearance(SignatureFieldAppearance).Note that in case you create new signature field (either use
SignerProperties.setFieldName(java.lang.String)with the name that doesn't exist in the document or don't specify it at all) then the signature is invisible by default.It is possible to set other appearance related properties such as
PdfSignatureFormField.setReuseAppearance(boolean),PdfSignatureFormField.setBackgroundLayer(com.itextpdf.kernel.pdf.xobject.PdfFormXObject)(n0 layer) andPdfSignatureFormField.setSignatureAppearanceLayer(com.itextpdf.kernel.pdf.xobject.PdfFormXObject)(n2 layer) for the signature field usinggetSignatureField(). Page, rectangle and other properties could be set up viaSignerProperties.- Returns:
SignatureFieldAppearanceobject representing signature appearance
-
populateExistingSignatureFormField
protected PdfSigFieldLock populateExistingSignatureFormField(PdfAcroForm acroForm)
Populates already existing signature form field in the acroForm object. This method is called during thepreClose(Map)method if the signature field already exists.- Parameters:
acroForm-PdfAcroFormobject in which the signature field will be populated- Returns:
- signature field lock dictionary
-
createNewSignatureFormField
protected PdfSigFieldLock createNewSignatureFormField(PdfAcroForm acroForm, java.lang.String name)
Creates new signature form field and adds it to the acroForm object. This method is called during thepreClose(Map)method if the signature field doesn't exist.- Parameters:
acroForm-PdfAcroFormobject in which new signature field will be addedname- the name of the field- Returns:
- signature field lock dictionary
-
getRangeStream
protected java.io.InputStream getRangeStream() throws java.io.IOExceptionGets the document bytes that are hashable when using external signatures. The general sequence is:preClose(Map),getRangeStream()andclose(PdfDictionary).- Returns:
- the
InputStreamof bytes to be signed - Throws:
java.io.IOException- if some I/O problem occurs
-
close
protected void close(PdfDictionary update) throws java.io.IOException
This is the last method to be called when using external signatures. The general sequence is: preClose(), getDocumentBytes() and close().update is a PdfDictionary that must have exactly the same keys as the ones provided in
preClose(Map).- Parameters:
update- a PdfDictionary with the key/value that will fill the holes defined inpreClose(Map)- Throws:
java.io.IOException- on error
-
getUnderlyingSource
protected IRandomAccessSource getUnderlyingSource() throws java.io.IOException
Returns the underlying source.- Returns:
- the underlying source
- Throws:
java.io.IOException- if some I/O problem occurs
-
addDocMDP
protected void addDocMDP(PdfSignature crypto)
Adds keys to the signature dictionary that define the certification level and the permissions. This method is only used for Certifying signatures.- Parameters:
crypto- the signature dictionary
-
addFieldMDP
protected void addFieldMDP(PdfSignature crypto, PdfSigFieldLock fieldLock)
Adds keys to the signature dictionary that define the field permissions. This method is only used for signatures that lock fields.- Parameters:
crypto- the signature dictionaryfieldLock- thePdfSigFieldLockinstance specified the field lock to be set
-
documentContainsCertificationOrApprovalSignatures
protected boolean documentContainsCertificationOrApprovalSignatures()
Check if current document instance already contains certification or approval signatures.- Returns:
trueif document contains certification or approval signatures,falseotherwise
-
getWidgetRectangle
protected Rectangle getWidgetRectangle(PdfWidgetAnnotation widget)
Get the rectangle associated to the provided widget.- Parameters:
widget- PdfWidgetAnnotation to extract the rectangle from- Returns:
- Rectangle
-
getWidgetPageNumber
protected int getWidgetPageNumber(PdfWidgetAnnotation widget)
Get the page number associated to the provided widget.- Parameters:
widget- PdfWidgetAnnotation from which to extract the page number- Returns:
- page number
-
applyAccessibilityProperties
protected void applyAccessibilityProperties(PdfFormField formField, IAccessibleElement modelElement, PdfDocument pdfDocument)
AppliesAccessibilityPropertiesfor provided signature field.- Parameters:
formField-PdfFormFieldthe form field to which the accessibility properties should be appliedmodelElement-IAccessibleElementthe form field layout element with accessibility propertiespdfDocument-PdfDocumentthe document to which the form field belongs
-
createSignatureDictionary
PdfSignature createSignatureDictionary(boolean includeDate)
-
embedMacTokenIntoSignatureContainer
byte[] embedMacTokenIntoSignatureContainer(byte[] signatureContainer) throws java.io.IOException- Throws:
java.io.IOException
-
embedMacTokenIntoSignatureContainer
static byte[] embedMacTokenIntoSignatureContainer(byte[] signatureContainer, java.io.InputStream rangeStream, PdfDocument document)
-
getSignerName
private static java.lang.String getSignerName(java.security.cert.X509Certificate certificate)
-
updateFieldName
private void updateFieldName()
-
isDocumentPdf2
private boolean isDocumentPdf2()
-
applyDefaultPropertiesForTheNewField
private void applyDefaultPropertiesForTheNewField(PdfSignatureFormField sigField)
-
setContent
private void setContent()
-
generateSignatureText
private SignedAppearanceText generateSignatureText()
-
populateExistingModelElement
private void populateExistingModelElement()
-
fillInAppearanceText
private void fillInAppearanceText(SignedAppearanceText appearanceText)
-
getFieldName
private java.lang.String getFieldName()
-
-