PdfFileSignature 类
Contents
[
Hide
]
准备 PDF 数字签名助手
在对 PDF 应用数字签名之前,最佳实践是设置一组可重用的辅助函数。这些函数封装了常见任务——例如初始化签名处理程序、定义签名的可视位置以及配置基于证书的签名——从而使您的主要签名逻辑保持简洁、一致且易于维护。
此设置实现的目标
此辅助层准备了顺畅签名工作流所需的一切:
- 初始化 PdfFileSignature 对象并将其绑定到文档
- 定义签名在页面上的显示位置
- 加载并应用签名证书
- 创建带有元数据的可重用 PKCS#7 签名对象
- 自定义签名的视觉外观
import aspose.pdf as ap
import aspose.pdf.facades as pdf_facades
import aspose.pydrawing as apd
DEFAULT_CERTIFICATE_PASSWORD = "Aspose2021"
DEFAULT_SIGNATURE_NAME = "Signature1"
def create_pdf_file_signature(infile):
pdf_signature = pdf_facades.PdfFileSignature()
pdf_signature.bind_pdf(infile)
return pdf_signature
def create_signature_rectangle():
return apd.Rectangle(10, 10, 200, 60)
def configure_signature_certificate(
pdf_signature, certificate_path, certificate_password=DEFAULT_CERTIFICATE_PASSWORD
):
pdf_signature.set_certificate(certificate_path, certificate_password)
def create_pkcs7_signature(
certificate_path, certificate_password=DEFAULT_CERTIFICATE_PASSWORD
):
signature = ap.forms.PKCS7(certificate_path, certificate_password)
signature.reason = "Document approval"
signature.contact_info = "qa@example.com"
signature.location = "New York, USA"
signature.authority = "Aspose.PDF Example"
return signature
def create_custom_signature_appearance():
appearance = ap.forms.SignatureCustomAppearance()
appearance.font_family_name = "Arial"
appearance.font_size = 10
appearance.show_contact_info = True
appearance.show_location = True
appearance.show_reason = True
return appearance