Create PDF Forms via C#

Create acroforms in PDF programmatically using Aspose.PDF for .NET Library

How to create PDF forms using C#

In order to create PDF Forms (Acroforms) in PDF file, we’ll use Aspose.PDF for .NET API which is a feature-rich, powerful and easy to use document manipulation API for C# platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

How to Create AcroForm in PDF using C#


You need Aspose.PDF for .NET to try the code in your environment.

  1. Load PDF in an instance of Document class.
  2. Create a field.
  3. Create decorations (like Border).
  4. Add field to the document and save modified PDF

Create PDF Forms in PDF - C#

This sample code shows how to Create PDF Forms in PDF using C#

    // 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);