PDF 表單。透過 Python 進行管理

在 Python via .NET 資源庫中使用 Aspose.PDF 管理 PDF 文件中的 Acroform

如何在 Python via .NET 資源庫使用 Aspose.PDF 管理 PDF 表單

為了在 PDF 文件中添加 PDF 表單(Acroforms),我們將使用 Aspose.PDF for Python via .NETAPI,該 API 是用於 Python 應用程序的功能豐富,功能強大且易於使用的文檔操作 API。您可以直接從 PyPI軟件包管理器下載其最新版本,搜索 ** aspose-pdf** 並安裝。您也可以從控制台或終端使用下列命令。

Console

pip install aspose-pdf

如何使用 Python 創建 PDF 表單

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

1.在文件類別的執行個體中載入 PDF。 1.通過其索引訪問頁面。 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)