Pra*_*nab 5 python pdf pdf-generation digital-signature
为了能够使用基于令牌的 DSC 对 PDF 文档进行签名,我的 PDF 中需要一个所谓的签名字段。
这是一个矩形区域,您可以使用例如 Adobe Reader 或 Adobe Acrobat 用数字签名填充。
我想用 Python 创建这个可签名的 PDF。
我从纯文本或 .docx 格式的富文本文档(图像和文本)开始。
如何在 Python 中使用此字段生成 PDF 文件?
小智 5
查看 pyHanko。您可以使用 Python 添加、编辑 PDF 并对其进行数字签名。
https://github.com/MatthiasValvekens/pyHanko
它是完全免费的。如果您有任何问题,Matthias 会非常乐于助人并且积极响应。
不幸的是,我找不到任何(免费)解决方案。只是签署 PDF 文档的 Python 程序。
但是有一个名为PDFTron的 Python PDF SDK可以免费试用。以下是特定文章的链接,显示如何“将认证签名字段添加到 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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3613 次 |
| 最近记录: |