I am trying to digitally sign a PDF file using PDFBox Library using Java with visible text to appear on a signature field like the attached image. I tried the following code and I get the following warning,
WARN org.apache.pdfbox.pdmodel.interactive.form.PDSignatureField - Appearance generation for signature fields not yet implemented - you need to generate/update that manually
Following is the code,
PDDocument pDDocument = PDDocument.load(new File("input.pdf"));
PDDocumentCatalog pDDocumentCatalog = pDDocument.getDocumentCatalog();
PDAcroForm pDAcroForm = pDDocumentCatalog.getAcroForm();
PDSignatureField pDSignatureField = (PDSignatureField) pDAcroForm.getField("signatureField");
PDSignature pDSignature = new PDSignature();
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(new FileInputStream("pfxfile.pfx"), "password".toCharArray());
byte[] bytes = IOUtils.toByteArray(new FileInputStream("pfxfile.pfx"));
pDSignature.setContents(bytes);
pDSignatureField.setValue(pDSignature);
FileOutputStream fileOutputStream = new FileOutputStream("output.pdf");
pDDocument.saveIncremental(fileOutputStream);
So what is I am doing wrong here? Or are there any solution apart from PDFBox?
