Class CreateVisibleSignature2
java.lang.Object
org.apache.pdfbox.examples.signature.CreateSignatureBase
org.apache.pdfbox.examples.signature.CreateVisibleSignature2
- All Implemented Interfaces:
SignatureInterface
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.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreateVisibleSignature2(KeyStore keystore, char[] pin) Initialize the signature creator with a keystore (pkcs12) and pin that should be used for the signature. -
Method Summary
Modifier and TypeMethodDescriptionprivate PDRectanglecreateSignatureRectangle(PDDocument doc, Rectangle2D humanRect) private InputStreamcreateVisualSignatureTemplate(PDDocument srcDoc, int pageNum, PDRectangle rect, PDSignature signature) private PDSignaturefindExistingSignature(PDAcroForm acroForm, String sigFieldName) booleanstatic voidArguments are [0] key store [1] pin [2] document that will be signed [3] image of visible signaturevoidsetImageFile(File imageFile) voidsetLateExternalSigning(boolean lateExternalSigning) Set late external signing.voidsignPDF(File inputFile, File signedFile, Rectangle2D humanRect, String tsaUrl) Sign pdf file and create new file that ends with "_signed.pdf".voidsignPDF(File inputFile, File signedFile, Rectangle2D humanRect, String tsaUrl, String signatureFieldName) Sign pdf file and create new file that ends with "_signed.pdf".private static voidusage()This will print the usage for this program.Methods inherited from class org.apache.pdfbox.examples.signature.CreateSignatureBase
getCertificateChain, isExternalSigning, setCertificateChain, setExternalSigning, setPrivateKey, setTsaUrl, sign
-
Field Details
-
signatureOptions
-
lateExternalSigning
private boolean lateExternalSigning -
imageFile
-
-
Constructor Details
-
CreateVisibleSignature2
public CreateVisibleSignature2(KeyStore keystore, char[] pin) throws KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, IOException, 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:
KeyStoreException- if the keystore has not been initialized (loaded)NoSuchAlgorithmException- if the algorithm for recovering the key cannot be foundUnrecoverableKeyException- if the given password is wrongCertificateException- if the certificate is not valid as signing timeIOException- if no certificate could be found
-
-
Method Details
-
getImageFile
-
setImageFile
-
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(File inputFile, File signedFile, Rectangle2D humanRect, String tsaUrl) throws 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:
IOException
-
signPDF
public void signPDF(File inputFile, File signedFile, Rectangle2D humanRect, String tsaUrl, String signatureFieldName) throws 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 urlsignatureFieldName- optional name of an existing (unsigned) signature field- Throws:
IOException
-
createSignatureRectangle
-
createVisualSignatureTemplate
private InputStream createVisualSignatureTemplate(PDDocument srcDoc, int pageNum, PDRectangle rect, PDSignature signature) throws IOException - Throws:
IOException
-
findExistingSignature
-
main
public static void main(String[] args) throws KeyStoreException, CertificateException, IOException, NoSuchAlgorithmException, UnrecoverableKeyException Arguments are [0] key store [1] pin [2] document that will be signed [3] image of visible signature- Parameters:
args-- Throws:
KeyStoreExceptionCertificateExceptionIOExceptionNoSuchAlgorithmExceptionUnrecoverableKeyException
-
usage
private static void usage()This will print the usage for this program.
-