将可填充的Python pdf转换为只读,就像浏览器的save_as_pdf功能

问题描述 投票:0回答:1

我正在使用 python pypdf 库填写我的 pdf 表单字段,并将其发送到 DocuSign 进行签名。Docusign 将 pdf 字段转换为只读,但缩小了其格式,这不是我想要的。由于我的 pdf 是可填写的表单,如果我在 chrome 中填写它并使用 chrome save_as_pdf 功能。它为我的表单制作了一个只读 pdf 文件,DocuSign 可以正确读取该文件,而不会破坏 pdf 的格式。即使当我尝试使用 pypdf writer 标志将 pdf 更改为只读时,我得到的 pdf 格式也不正确。

我已经尝试了所有可能的pdf库将我的pdf转换为只读pdf,就像浏览器的save_as_pdf功能一样,但一切都是徒劳的。如果我可以像浏览器一样转换本地文件,然后将字节推送到 DocuSign,我希望它能正常工作。

#Code to fill pdf and write to file
reader = PdfReader("wphg_form.pdf")
# reader = PdfReader("form.pdf")
writer = PdfWriter()
writer.append(reader)
writer.update_page_form_field_values(writer.pages[0],  fields={
                "DEPOT_NR": "1111111111",
            })
with open("filled-out.pdf", "wb") as output_stream:
    writer.write(output_stream)
python pdf pdf-generation docusignapi pypdf4
1个回答
0
投票

对于类似的事情,您需要创建 10 个文本字段,而不仅仅是一个。

基本上,您可以使用一个循环来完成此操作,将它们一个接一个地添加,并将每个字段向右推约 40 像素(您需要通过反复试验找出确切的数字)。

然后填写值并使其只读(如果需要)

这是让您了解想法的粗略代码:

for x in range(10):
  text_box = Text(
  anchor_string="Depot", anchor_units="pixels",
  anchor_y_offset="-10", anchor_x_offset=300+x*5,
  font="helvetica", font_size="size11",
  bold="true", value=args["signer_name"],
  locked="true", tab_id="Textbo" + x,
  tab_label="Textbo" + x)
© www.soinside.com 2019 - 2024. All rights reserved.