Unable to read the signature field

Hi All,

I’m facing an issue like I was not able to read the signature field value using PDFTron python SDK.

Signature field

Screenshot from 2021-02-12 09-46-58.png

When I click sign here, it pops up a window where I can draw, type or upload my signature image.
Screenshot from 2021-02-12 09-47-13.png
If I click create, then the value occurs there.

Screenshot from 2021-02-12 09-47-30.png

So in python code, I was reading the signature field and checked the type of field.
Trying to get the value of the field using the code

field_value = field.GetValue()

And also i create using field_value = field.GetValueAsString()

But I’m getting a null value from that.

Seeking your help folks, Help me.

Thanks in advance
Karthikeyan B

If you added the signature using WebViewer, then the signature is actually added over top of the Digital Signature field with a Freehand/Ink annotation.

You can track the bounding boxes of the signature field, and look for an Ink annotation that has the same bounding box.

See this sample code on how to iterate Ink annots.
https://www.pdftron.com/documentation/samples/py/AnnotationTest

Hi Ryan,

I tried the approach but it’s working for text or image upload, not for drawing.

Here is the code which I’m trying.

 itr = doc.GetFieldIterator()
    while itr.HasNext():
        if itr.Current().GetType() == Field.e_signature and itr.Current().IsAnnot():
            signature_found = False

            print("Signature field name: " + itr.Current().GetName())
        

            print("Traversing all annotations in the document...")
            page_num = 1
            page_itr = doc.GetPageIterator()

            sig_widget = Annot(itr.Current().GetSDFObj())
            sig_widget_rect = sig_widget.GetRect()

            while page_itr.HasNext():
                page_num = page_num + 1
                page = page_itr.Current()
                num_annots = page.GetNumAnnots()
                i = 0
                while i < num_annots:
                    annot = page.GetAnnot(i)
                    if not annot.IsValid():
                        continue

                    if annot.GetType() == Annot.e_Ink or annot.GetType() == Annot.e_Stamp:
                       ink_rect = annot.GetRect() 
                       if (sig_widget_rect.Contains(ink_rect.x1, ink_rect.y1) or
                           sig_widget_rect.Contains(ink_rect.x1, ink_rect.y2) or
                           sig_widget_rect.Contains(ink_rect.x2, ink_rect.y1) or
                           sig_widget_rect.Contains(ink_rect.x2, ink_rect.y2)):
                        signature_found = True    

                    i = i + 1
                page_itr.Next()

            print()
            if signature_found:
                print("Signature found")
            else:
                print("No signature found")

            print("------------------------------")
        itr.Next()

contract_sign.pdf (32.8 KB)

Sorry, its unclear what you are describing now.

Could you please elaborate on exactly what you get, and what you expected to get instead, with regards to the code you provided and the corresponding PDF.