为了能够使用基于令牌的DSC签署PDF文档,我需要一个所谓的签名字段在我的PDF。
这是一个矩形字段,您可以使用Adobe或Acrobat填充数字签名。
我想用Python创建这个可指示的PDF。
我从纯文本开始,或者是.docx格式的富文本文档(图像和文本)。
如何在Python中使用此字段生成PDF文件?
发布于 2020-05-14 02:38:38
不幸的是,我找不到任何(免费)解决方案。只是签署PDF文档的Python程序。
但是有一个叫做PDFTron的Python,它有一个免费的试用版。下面是一篇特定文章的链接,该文章展示了如何“将证书签名字段添加到PDF文档并对其签名”。
# Open an existing PDF
doc = PDFDoc(docpath)
page1 = doc.GetPage(1)
# Create a text field that we can lock using the field permissions feature.
annot1 = TextWidget.Create(doc.GetSDFDoc(), Rect(50, 550, 350, 600), "asdf_test_field")
page1.AnnotPushBack(annot1)
# Create a new signature form field in the PDFDoc. The name argument is optional;
# leaving it empty causes it to be auto-generated. However, you may need the name for later.
# Acrobat doesn't show digsigfield in side panel if it's without a widget. Using a
# Rect with 0 width and 0 height, or setting the NoPrint/Invisible flags makes it invisible.
certification_sig_field = doc.CreateDigitalSignatureField(cert_field_name)
widgetAnnot = SignatureWidget.Create(doc, Rect(0, 100, 200, 150), certification_sig_field)
page1.AnnotPushBack(widgetAnnot)
...
# Save the PDFDoc. Once the method below is called, PDFNet will also sign the document using the information provided.
doc.Save(outpath, 0)
发布于 2021-09-21 18:47:22
看看pyHanko。您可以使用Python添加、编辑和数字签名PDF。
https://github.com/MatthiasValvekens/pyHanko
完全免费。如果你有任何问题,马提亚斯是非常有帮助和反应。
发布于 2020-05-17 13:56:42
我使用python的signpdf库来签署pdf。
阅读本文档以更好地理解https://github.com/yourcelf/signpdf
pip install signpdf
演示:-在"contract.pdf“的第一页签名为"sig.png":->
signpdf contract.pdf sig.png --coords 1x100x100x150x40
理解协调:- Github链接
https://stackoverflow.com/questions/61606279
复制相似问题