简体   繁体   中英

PDFBox: reference existing signature (field) when signing

I am trying to figure out whether PDFBox supports signing of existing (emtpy) signature form fields. I checked the examples provided however all only seem to add new fields. There was another post where the OP states:

"Pre-existing signature fields are not affected by pdfbox as pdfbox appears not to be able to reference them."

Then however this has been written a year ago and there seems to be some effort on the signature functionality. So can anyone tell me the if it is possible (if so how) to reference existings signature fields? Or maybe it is planned?

Update I implemented as you suggested the following functionality:

PDDocumentCatalog docCatalog = doc.getDocumentCatalog();
PDAcroForm acroForm = docCatalog.getAcroForm();
PDField field = acroForm.getField("exampleSignature");
PDSignature signature = ((PDSignatureField)field).getSignature();

However signature is alway null . After checking the PDF spec it perfectly makes sense, since empty signature fields never have the signature dictionary set. When adding a signature dictionary eg the values for the filter, Contents, ByteRange etc. must be filled but can only be filled with meaningfull values to the time of signing...

Starting with 2.0.4, but already in the snapshot builds , it is possible to sign existing (empty) signature form fields. (It will not work with 2.0.3, even if you use the updated code example from upcoming 2.0.4, because the library code had several bugs that have been fixed). The example code can be found here . Two things are new in the example code:

  • visibleSignatureProperties.buildSignature(); has been moved
  • a call signature = findExistingSignature(doc, "Signature1"); has been added.

What this does is to search for the signature field named "Signature1", and if found, it creates a signature dictionary (the /V component). Because this signature object is passed to the doc.addSignature() call, PDFBox will be able to detect that the parent field already exists and won't create a new one.

More details can be found in PDFBOX-3525 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM