可通过 Python 填写的 PDF 表单

通过 Python 创建可填写的 PDF 表单。使用服务器端 API 构建自己的 Python for .NET 应用程序

如何使用 Python for .NET 库填写 PDF 表单

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

如何使用 Python 在 PDF 中填写 AcroForm


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

  1. 在文件類的實例中載入 PDF。
  2. 在 PDF 檔案中建立一個字段。
  3. 向文件添加欄位。
  4. 保存修改後的 PDF

在 PDF 中填写 AcroForm-Python

此示例代码显示如何使用 Python 在 PDF 中填写 PDF 表单

    // Step 1. Open document
    Document pdfDocument = new Document(dataDir + "FillFormField.pdf");

    // Step 2. Get a field
    TextBoxField textBoxField = pdfDocument.Form["textbox1"] as TextBoxField;

    // Step 3. Modify field value
    textBoxField.Value = "Value to be filled in the field";
    dataDir = dataDir + "FillFormField_out.pdf";

    // Step 4. Save updated document
    pdfDocument.Save(dataDir);