为了能够使用基于令牌的DSC对PDF文档进行签名,我在我的PDF中需要一个所谓的签名字段。
这是一个矩形字段,您可以使用例如Adobe Reader或Adobe Acrobat。
我想用Python创建这个可签名的PDF。
我从纯文本或.docx格式的富文本文档(图像和文本)开始。
如何在Python中使用此字段生成PDF文件?
[不幸的是,我找不到任何(免费的)解决方案。只是签署PDF文档的Python程序。
但是有一个名为PDFTron的Python PDF SDK,可以免费试用。这是一篇特定文章的link,显示了如何“向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)
我使用python的signpdf库对pdf进行签名。
请参阅此链接以更好地理解https://github.com/yourcelf/signpdf
pip install signpdf
演示:-在“ contract.pdf”的首页上签名“ sig.png”:->
signpdf contract.pdf sig.png --coords 1x100x100x150x40
unstandstand坐标:-Github link