通过 Python 创建 PDF 表单

使用适用于 Python for .NET 库的 Aspose.PDF 以编程方式在 PDF 中创建 acroforms

如何使用 Python 创建 PDF 表单

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

如何使用 Python 在 PDF 中创建 AcroForm


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

1。在 Document 类的实例中加载 PDF。 1。创建字段。 1。创建装饰(如边框)。 1。向文档添加字段并保存修改后的 PDF

在 PDF 中创建 PDF 表单-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)
document = apdf.Document(path_infile)

# Create a new text box field
rectange = apdf.Rectangle(100, 100, 200, 120, True)
textBoxField = apdf.forms.TextBoxField(document.pages[1], rectange)
textBoxField.partial_name = "textbox1"
textBoxField.value = "Text Box"

# Customize the border of the text box field
border = apdf.annotations.Border(textBoxField)
border.width = 3
border.dash = apdf.annotations.Dash(1, 1)
textBoxField.border = border

# Set the color of the text box field
textBoxField.color = apdf.Color.dark_green

# Add the text box field to the form
document.form.add(textBoxField, 1)

# Save the modified PDF document
document.save(path_outfile)