How do I check if all signature fields on a PDF form have been signed?

263 views
Skip to first unread message

Support

unread,
May 28, 2013, 5:32:58 PM5/28/13
to pdfne...@googlegroups.com
Q:
We need a quick check that all signature fields on a PDF form have been signed. Is this something that can done via the PDFtron SDK?
 
------------
A:
 
In check if all signature fields have been signed, you will need to iterate through the list of fields using PDFDoc.GetFieldIterator (or if you are interested in only a given page iterate through page annotations as shown in Annotation sample, filtering Widget annotations with subtype e_signature). As you go through each field, you can filter them by the type (i.e. Field.Type.e_signature). Once you hit a signature field, you can check whether this field contains a "/V" key. You can do this by checking Field.GetValue() != null. A sample pseudo code would be the following:

using (PDFDoc doc = new PDFDoc("MyDoc.pdf")) {
   
var fieldItr = doc.GetFieldIterator();
   
for ( ; fieldItr.HasNext(); ) {
       
var field = itr.Next();
       
if (field.GetType == Field.Type.e_signature) {
           
if (field.GetValue() == null) {
               
// One of the signature fields does not have a signature.
            }
        }
    }
}


TimA

unread,
Dec 4, 2013, 4:22:01 PM12/4/13
to pdfne...@googlegroups.com
I have tried this but whether or not the field is signed I get a non-null value returned from the getValue() call. What can be the issue here?
Message has been deleted

Vincent Ycasas

unread,
Jun 20, 2017, 6:07:19 PM6/20/17
to pdfne...@googlegroups.com
It is possible that it returns an empty dictionary. If such is the case, then field.GetValue() will not return null.

To check for these kinds of situations, you will need to slightly modify the code:

using (PDFDoc doc = new PDFDoc("MyDoc.pdf")) {
    var fieldItr = doc.GetFieldIterator();
    for ( ; fieldItr.HasNext(); ) {
        var field = itr.Next();
        if (field.GetType == Field.Type.e_signature) {
            if (field.GetValue() == null) {
                // One of the signature fields does not have a signature.
            }
            else {
                // Check if the value contains an entry for /ByteRange. The /ByteRange key is necessary for adding digital signatures and is a required field.
                var valueObj = field.GetValue();
                if (valueObj.IsDict()) { // The value must be a dictionary object.
                    if (valueObj.Find("Contents") != null) {
                        // This field is signed.
                    }
                }
                // Alternatively, you can check for the existence of /ByteRange and /Filter keys.
                // Please see PDF Reference for more information.
            }
        }
    }
}
Reply all
Reply to author
Forward
0 new messages