首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用python创建包含签名字段的PDF文件?

如何使用python创建包含签名字段的PDF文件?
EN

Stack Overflow用户
提问于 2020-05-05 05:23:21
回答 4查看 7.9K关注 0票数 5

为了能够使用基于令牌的DSC签署PDF文档,我需要一个所谓的签名字段在我的PDF。

这是一个矩形字段,您可以使用Adobe或Acrobat填充数字签名。

我想用Python创建这个可指示的PDF。

我从纯文本开始,或者是.docx格式的富文本文档(图像和文本)。

如何在Python中使用此字段生成PDF文件?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2020-05-14 02:38:38

不幸的是,我找不到任何(免费)解决方案。只是签署PDF文档的Python程序。

但是有一个叫做PDFTron的Python,它有一个免费的试用版。下面是一篇特定文章的链接,该文章展示了如何“将证书签名字段添加到PDF文档并对其签名”。

代码语言:javascript
运行
复制
# 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)
票数 1
EN

Stack Overflow用户

发布于 2021-09-21 18:47:22

看看pyHanko。您可以使用Python添加、编辑和数字签名PDF。

https://github.com/MatthiasValvekens/pyHanko

完全免费。如果你有任何问题,马提亚斯是非常有帮助和反应。

票数 2
EN

Stack Overflow用户

发布于 2020-05-17 13:56:42

我使用python的signpdf库来签署pdf。

阅读本文档以更好地理解https://github.com/yourcelf/signpdf

代码语言:javascript
运行
复制
pip install signpdf

演示:-在"contract.pdf“的第一页签名为"sig.png":->

代码语言:javascript
运行
复制
signpdf contract.pdf sig.png --coords 1x100x100x150x40

理解协调:- Github链接

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61606279

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档