透過 Python 建立 PDF 表格

使用 Aspose.PDF 以編程方式為 Python for .NET 程式庫建立 PDF 中的橫向形式

如何使用 Python 創建 PDF 表單

為了在 PDF 文件中創建 PDF 表單(Acroforms),我們將使用 [Aspose.PDF 用於 Python 通過 .NET](https://products.aspose.com/pdf/python-net)API,該 API 是用於 Python 應用程序的功能豐富,功能強大且易於使用的文檔操作 API。您可以直接從 [PyPI](https://pypi.org/)軟件包管理器下載其最新版本,搜索 ** aspose-pdf** 並安裝。您也可以從控制台或終端使用下列命令。

如何使用 Python 在 PDF 中創建 AcroForm


您需要 [Aspose.PDF for Python via .NET](https://releases.aspose.com/pdf/pythonnet/)來嘗試您的環境中的代碼。

1.在文件類別的執行個體中載入 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)