Class CreateVisibleSignature2

  • All Implemented Interfaces:
    org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface

    public class CreateVisibleSignature2
    extends CreateSignatureBase
    This is a second example for visual signing a pdf. It doesn't use the "design pattern" influenced PDVisibleSignDesigner, and doesn't create its complex multilevel forms described in the Adobe document Digital Signature Appearances, because this isn't required by the PDF specification. See the discussion in December 2017 in PDFBOX-3198.
    Author:
    Vakhtang Koroghlishvili, Tilman Hausherr
    • Constructor Summary

      Constructors 
      Constructor Description
      CreateVisibleSignature2​(java.security.KeyStore keystore, char[] pin)
      Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature.
    • Constructor Detail

      • CreateVisibleSignature2

        public CreateVisibleSignature2​(java.security.KeyStore keystore,
                                       char[] pin)
                                throws java.security.KeyStoreException,
                                       java.security.UnrecoverableKeyException,
                                       java.security.NoSuchAlgorithmException,
                                       java.io.IOException,
                                       java.security.cert.CertificateException
        Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature.
        Parameters:
        keystore - is a pkcs12 keystore.
        pin - is the pin for the keystore / private key
        Throws:
        java.security.KeyStoreException - if the keystore has not been initialized (loaded)
        java.security.NoSuchAlgorithmException - if the algorithm for recovering the key cannot be found
        java.security.UnrecoverableKeyException - if the given password is wrong
        java.security.cert.CertificateException - if the certificate is not valid as signing time
        java.io.IOException - if no certificate could be found
    • Method Detail

      • getImageFile

        public java.io.File getImageFile()
      • setImageFile

        public void setImageFile​(java.io.File imageFile)
      • isLateExternalSigning

        public boolean isLateExternalSigning()
      • setLateExternalSigning

        public void setLateExternalSigning​(boolean lateExternalSigning)
        Set late external signing. Enable this if you want to activate the demo code where the signature is kept and added in an extra step without using PDFBox methods. This is disabled by default.
        Parameters:
        lateExternalSigning -
      • signPDF

        public void signPDF​(java.io.File inputFile,
                            java.io.File signedFile,
                            java.awt.geom.Rectangle2D humanRect,
                            java.lang.String tsaUrl)
                     throws java.io.IOException
        Sign pdf file and create new file that ends with "_signed.pdf".
        Parameters:
        inputFile - The source pdf document file.
        signedFile - The file to be signed.
        humanRect - rectangle from a human viewpoint (coordinates start at top left)
        tsaUrl - optional TSA url
        Throws:
        java.io.IOException
      • signPDF

        public void signPDF​(java.io.File inputFile,
                            java.io.File signedFile,
                            java.awt.geom.Rectangle2D humanRect,
                            java.lang.String tsaUrl,
                            java.lang.String signatureFieldName)
                     throws java.io.IOException
        Sign pdf file and create new file that ends with "_signed.pdf".
        Parameters:
        inputFile - The source pdf document file.
        signedFile - The file to be signed.
        humanRect - rectangle from a human viewpoint (coordinates start at top left)
        tsaUrl - optional TSA url
        signatureFieldName - optional name of an existing (unsigned) signature field
        Throws:
        java.io.IOException
      • main

        public static void main​(java.lang.String[] args)
                         throws java.security.KeyStoreException,
                                java.security.cert.CertificateException,
                                java.io.IOException,
                                java.security.NoSuchAlgorithmException,
                                java.security.UnrecoverableKeyException
        Arguments are [0] key store [1] pin [2] document that will be signed [3] image of visible signature
        Parameters:
        args -
        Throws:
        java.security.KeyStoreException
        java.security.cert.CertificateException
        java.io.IOException
        java.security.NoSuchAlgorithmException
        java.security.UnrecoverableKeyException