0

I want to sign a PDF document. I find a way to do it with pyHanko, but the signature is not visible.

I think it's because the field containing the signature is invisible. When I look into the properties of the signature, it says that the field is invisible.

Do you have any idea why the signature (and the field) keep being invisible ?

I tried this code, and I was expecting having my pdf document signed on the first page. it's a function that take the path to the pdf document needed to be signed as parameter. (I just followed this example : https://pyhanko.readthedocs.io/en/latest/lib-guide/signing.html#text-based-stamps)

def sign_ac(path):
    path_cert = "path to my cert.pfx"
    signer = signers.SimpleSigner.load_pkcs12(pfx_file=path_cert, passphrase=b'mdp')
    with open(path, 'rb') as doc:
        w = IncrementalPdfFileWriter(doc, strict=False)
        append_signature_field(w,
                               sig_field_spec=SigFieldSpec(sig_field_name="Signa1", box=(100, 100, 100, 100),
                                                           visible_sig_settings=VisibleSigSettings(rotate_with_page=True)),
                               )
        meta = signers.PdfSignatureMetadata(field_name='Signa1')
        pdf_signer = signers.PdfSigner(
            meta, signer=signer, stamp_style=stamp.TextStampStyle(
                stamp_text='Thus is custom text!\nSigned by: %(signer)s\nTime: %(ts)s',
                text_box_style=text.TextBoxStyle(
                    font=opentype.GlyphAccumulatorFactory('path to font police.ttf'),
                ),
                background=images.PdfImage('path to img.jpg')
            )
        )
        with open('path to signed doc.pdf', 'wb') as outf:
            pdf_signer.sign_pdf(w, output=outf)

2 Answers2

0

The box coordinates, box=(100, 100, 100, 100), turned out to be the problem. My box was a point, so it was invisible.

append_signature_field(
    w,
    sig_field_spec=SigFieldSpec(
        sig_field_name="Signa1",
        box=(100, 100, 100, 100),
        visible_sig_settings=VisibleSigSettings(rotate_with_page=True)
    )
)

With the following snippet, the issue has been resolved:

append_signature_field(
    w,
    sig_field_spec=SigFieldSpec(
        sig_field_name="Signature",
        box=(200, 100, 400, 160),
        visible_sig_settings=VisibleSigSettings(rotate_with_page=True)
    )
)
ascpixi
  • 529
  • 4
  • 13
0

sig_field_spec=SigFieldSpec(sig_field_name="Signa1", box=(50, 50, 200, 200),

Try adjusting the box parameter and see if the signature field and signature become visible in the resulting PDF document.