如何在表单中添加管理风格的输入 (PDF)

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

我想用Python创建一个可填写输入的表单,格式如下(见附件)enter image description here

我尝试了几个不同的 pdf 库,但没有一个能够生成这样的输入。有人猜测哪个图书馆是用来生成这些表格的吗?我可以用 python 来做吗?

我在 blob 库上看了很多,还看了 aspose.pdf lib,但它根本不起作用

python forms pdf
1个回答
0
投票

有一些 python 库可以做到这一点,这是我使用过的一个:

from reportlab.pdfgen import canvas
from reportlab.pdfbase import pdfform

def create_fillable_form():
    c = canvas.Canvas("fillable_form.pdf")
    form = c.acroForm

    # Create a text field
    c.drawString(100, 700, "Name:")
    form.textfield(name='name', tooltip='Enter your name', x=150, y=690, width=200)

    # Create a checkbox
    c.drawString(100, 650, "Agree to terms:")
    form.checkbox(name='agree', tooltip='Check to agree', x=180, y=640)

    c.save()

create_fillable_form()

更多文档在这里

还有一些方法可以将 HTML 页面转换为 PDF(如果更简单的话)

© www.soinside.com 2019 - 2024. All rights reserved.