通过 C# 创建 PDF 表单

通过 C# 在文档中创建 PDF 表单。使用服务器端 API 构建您自己的 .NET 应用程序。

如何使用 C# 创建 PDF 表单

为了在 PDF 文件中创建 PDF 表单 (Acroforms),我们将使用 Aspose.PDF for .NET API,这是一款功能丰富、强大且易于使用的适用于 C# 平台的文档操作 API。打开 NuGet 包管理器,搜索aspose.pdf然后安装。您也可以使用包管理器控制台中的以下命令。

如何使用 C# 在 PDF 中创建 AcroForm


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

1.在 “文档” 类的实例中加载 PDF。 1.创建字段。 1.创建装饰品(如边框)。 1.在文档中添加字段并保存修改过的 PDF

在 PDF 中创建 PDF 表单-C#

此示例代码显示如何使用 C# 在 PDF 中创建 PDF 表单

    // Open document
    Document pdfDocument = new Document(dataDir + "TextField.pdf");

    // Create a field
    TextBoxField textBoxField = new TextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(100, 200, 300, 300));
    textBoxField.PartialName = "textbox1";
    textBoxField.Value = "Text Box";

    // Create decorations (like Border)
    Border border = new Border(textBoxField);
    border.Width = 5;
    border.Dash = new Dash(1, 1);
    textBoxField.Border = border;

    textBoxField.Color = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Green);

    // Add field to the document
    pdfDocument.Form.Add(textBoxField, 1);

    dataDir = dataDir + "TextBox_out.pdf";
    // Save modified PDF
    pdfDocument.Save(dataDir);