Warm tip: This article is reproduced from serverfault.com, please click

With iText Signature Fields (digital signature vs electronic signature image)

发布于 2020-12-07 14:50:59

I was trying to read signatures from a document, I see different signature types from itext (and adobe reader). I can read digital signatures with a certificate, etc. See the code below. But I also see signature type in a fillable PDF that comes out...seemingly as an image which I think is just an electronic signature. How do I read a signature (or maybe it is an image) to pull that signature data? Will it come out as an image, is there any metadata associated with that signature type?

Here is the code that I tried but came up as empty,

    AcroFields fields = reader.getAcroFields();
    ArrayList<String> names = fields.getSignatureNames();
Questioner
Berlin Brown
Viewed
0
mkl 2020-12-09 00:16:37

In General

The only kinds of signatures specified in the PDF specification ISO 32000-2 are certification signatures, approval signatures, document time stamps, and usage rights signatures. Usage rights signatures are merely a means to communicate to Adobe Reader that it shall enable certain usually inactive features; they are not meant to be created by users or validated as user signature. Thus, let's ignore them.

Certification signatures, approval signatures, and document time stamps are stored in AcroForm signature fields, and you retrieve the signature fields filled-in (signed) with interoperable signatures using your code.

Thus, the other "signatures" you recognize when viewing your PDF are

  • either not interoperable but at least signatures according to spec,
  • or they are not even signatures according to spec to start with,
  • or your PDF is broken making iText not recognize the signature.

In either case there is no generic way to find the signature related information of them and interpret it. You have to analyze the exact nature of the low-level data in your PDF and probably even have to ask the creator of the signature to provide sufficient information (specifications, decryption material, ...) to be able to analyze.

In Your Example File

In case of the example file you shared there is a mixture (as Lonzak already explained while I wrote this):

  • It has 6 empty (unsigned) signature fields.

  • And it has two bitmaps with scribbles located approximately in the area of two of the signature form fields.

    screen shot

Those bitmap images, therefore, do not fill any of the AcroForm form fields. Actually they do no represent any dynamic content at all, they are part of the static page content.

Nonetheless those bitmaps may count as legally binding (albeit easy to repudiate) signatures depending on your local legislation. Thus, there indeed may be a need to extract those scribbles even though they do not fill the official, AcroForm form fields.

To do so you have to apply image extraction (with coordinates) to your PDF. To identify which bitmap was used for which cause, you can compare those coordinates with the coordinates of the 6 empty signature fields.

Furthermore, the Adobe software used to add those scribbles even specially marked the added contents with a custom tag:

/ADBE_FillSign BMC
q
0 Tc
0 Tw
0 g
0 G
1 w
/GS2 gs
/T1_0 1 Tf
/Fm0 Do
Q
EMC

Thus, in custom code to find signature images like these you only need to find images referenced inside content marked as ADBE_FillSign. Obviously, though, this restricts your code to scribbled signatures added with Adobe software...

Further Questions

In comments you asked follow-up questions.

What is the recommended approach, say for our "clients" that sign the documents to use. They typically will use Mac Preview or Adobe Reader...to sign. For example, should they use the "text" signature?

This is first and foremost a legal question; you should ask your legal department or an external lawyer which kinds of electronic signatures are ok in your use case and which are not. Then you can select from the acceptable kinds of signatures those you are willing to support in your software and ask your clients to use either of them.

As I don't have a Mac, I have no hands-on experience with Mac Preview. Its role in a number of issues for the last few years suggests, though, that it is not a very faithful viewer. Thus, I would not recommend it here. But maybe it meanwhile has improved to usefulness.

Current Adobe Reader versions should be faithful enough to be recommended. But don't forget to clearly describe how to sign correctly with it.

Also, can multiple people digitally sign?

PDF interoperably supports serial digital signing. I.e. the first signer signs the PDF and forwards the PDF with his signature to the next one who signs the PDF with already one signature and forwards it, etc. etc. until the last signer has signed and you have a PDF with signatures by all signers.

It is not interoperably possibly for multiple signers to digitally sign in parallel. I.e. they cannot all sign the original, unsigned PDF and expect that their signatures can somehow be merged into a single PDF with all their signatures filled in.

What does a verified signature look like and can I have multiple?

(Only digital signatures can be verified, not arbitrary ones. Thus, I assume you refer to digital signatures here.)

How the visualization of a digital signature in a document looks, is completely custom and up to the signer.

Adobe Reader displays information on digital signatures on the Signatures panel on the left, e.g. like this (this screen shot is localized in Italian; you'll more likely see it in English)

The green checkmark and the text explain the verification status of the signature.

There are ways to construct a digital signature field so that Adobe Reader displays the verification checkmark in the signature in the document, e.g. like this:

You shouldn't go for this, though. This has been deprecated since Adobe Acrobat 6, more than a dozen years ago, and it has been forbidden by the current PDF standard, ISO 32000-2.