可通过 Python 填写的 PDF 表单

创建可填写的 PDF 表单。使用 Aspose.PDF for Python for .NET 以编程方式修改 PDF 文件

如何使用 Python 库填写 PDF 表单

为了在 PDF 文件中填写 PDF 表单 (Acroforms),我们将使用 Aspose.PDF for Python via .NET API,这是适用于 Python 应用程序的功能丰富、强大且易于使用的文档操作 API。你可以直接从 PyPI 包管理器下载其最新版本,搜索 aspose-pdf 然后安装。您也可以使用控制台或终端中的以下命令。

如何使用 Python 在 PDF 中填充 AcroForm


你需要 Aspose.PDF for .NET 才能在你的环境中试用代码。

1。在 Document 类的实例中加载 PDF。 1。在 PDF 文件中创建字段。 1。向文档添加字段。 1。保存修改后的 PDF

以 PDF 格式填写 AcroForm-Python

此示例代码说明如何使用 Python 以 PDF 格式填写 PDF 表单

import aspose.pdf as apdf

from os import path

path_infile = path.join(self.data_dir, infile)
path_outfile = path.join(self.data_dir, outfile)

# Define the new field values
new_field_values = {
    "First Name": "Alexander_New",
    "Last Name": "Greenfield_New",
    "City": "Yellowtown_New",
    "Country": "Redland_New",
}

# Create a Form object from the input PDF file
form = apdf.facades.Form(path_infile)

# Fill out the form fields with the new values
for formField in form.field_names:
    if formField in new_field_values:
        form.fill_field(formField, new_field_values[formField])

# Save the modified form to the output PDF file
form.save(path_outfile)