python - 如何使用 python 库 pdfrw 使 pdf 不可编辑
问题描述
我正在使用 pdfrw python 库从网络表单中填充 pdf 字段。然后我必须将它传递给电子签名网络服务,但他们希望 pdf 不可编辑(展平)。
我尝试使用 Adobe 将其展平,它可以工作,但是我无法通过我的 python 代码填充它..
import pdfrw
template_pdf = pdfrw.PdfReader(input_pdf_path)
annotations = template_pdf.pages[0]['/Annots']
for annotation in annotations:
if annotation['/Subtype'] == '/Widget':
if annotation['/T']:
key = annotation['/T'][1:-1]
if key in data_dict.keys():
annotation.update(
pdfrw.PdfDict(V='{}'.format(data_dict[key]))
)
template_pdf.Root.AcroForm.update(pdfrw.PdfDict(NeedAppearances=pdfrw.PdfObject('true')))
pdfrw.PdfFileWriter().write(output_pdf_path, template_pdf)
我的想法是在填充后使用 pdfrw 将 pdf 展平,但我真的不知道如何。如果有人遇到此问题并有解决方案,那将对我有很大帮助。
解决方案
if key in data_dict.keys():
annotation.update(pdfrw.PdfDict(V='{}'.format(data_dict[key])))
annotation.update(pdfrw.PdfDict(Ff=1)) # This set the annotation as as not editable
推荐阅读
- javers - 如何将自定义属性/标签添加到 JaVers 中的现有提交?
- html - “元素的 tabindex 不应大于零” - 非零 Tabindex 破坏验证和 508 合规性
- python - 如何获取字符串的第一个字符?
- java - 不能转换为 Java
- javascript - 从 API Gateway 和 Lambda 获取 Cognito ID
- java - 从 JPAQuery 获取本机 SQL 字符串
- c# - CS0103 Visual Studio 中仅包含文本框和按钮的简单项目中的错误
- swagger - 从 ApiControllers (C#, .Net 4.5) 生成 OpenApi 3
- python - 应用循环后原始数据帧没有变化
- r - 如何使用 sparklyr 获取跟踪作业 URL?