How to Add and Remove Form Fields in PDF via .NET

How to Add and Remove Form Fields in PDF via .NET

Learn to programmatically add and remove form fields—such as textboxes, checkboxes, and comboboxes—in your PDF files using the Aspose.PDF Form Editor Plugin for .NET. This practical guide helps automate AcroForm management for business, data collection, or workflow integration.


Introduction to AcroForms

AcroForms are interactive PDF forms that support user input (text, selection, signatures). Automating their creation or modification in .NET is a powerful way to build dynamic business applications or processing pipelines.


Adding Form Fields (C# Example)

Below, add a textbox, checkbox, and combobox to the first page of an existing PDF.

using Aspose.Pdf.Plugins;

string inputPath = @"C:\Samples\sample.pdf";
string outputPath = @"C:\Samples\sample_with_fields.pdf";

var plugin = new FormEditor();
var addOptions = new FormEditorAddOptions(
    new[] {
        // Textbox
        new FormTextBoxFieldCreateOptions(1, new Rectangle(10, 700, 90, 715)) {
            MaxLen = 20,
            Value = "Name",
            Color = Color.Brown
        },
        // Checkbox
        new FormCheckBoxFieldCreateOptions(1, new Rectangle(110, 700, 125, 715)) {
            Value = "Agree",
            PartialName = "CheckBox_Agree",
            Color = Color.Blue
        },
        // Combobox
        new FormComboBoxFieldCreateOptions(1, new Rectangle(310, 600, 350, 615)) {
            Color = Color.Red,
            Editable = true,
            DefaultAppearance = new DefaultAppearance("Arial Bold", 12, System.Drawing.Color.DarkGreen),
            Options = new[] {"Option1", "Option2", "Option3"},
            Selected = 1
        }
    });
addOptions.AddInput(new FileDataSource(inputPath));
addOptions.AddOutput(new FileDataSource(outputPath));
plugin.Process(addOptions);

Removing Form Fields

To remove fields by name or type:

var removeOptions = new FormEditorRemoveOptions(
    new[] { "CheckBox_Agree", "TextBoxField1" } // Field names to remove
);
removeOptions.AddInput(new FileDataSource(outputPath));
removeOptions.AddOutput(new FileDataSource(@"C:\Samples\sample_fields_removed.pdf"));
plugin.Process(removeOptions);

Saving Results

Always specify the output file in your options to save a new, updated PDF. Verify the changes using any PDF viewer or further automation.


Use Cases

  • Build custom intake forms for business, healthcare, education
  • Auto-generate consent or registration PDFs
  • Batch-remove legacy fields from archived forms

Frequently Asked Questions

Q: Can I undo field changes after saving? A: PDF edits are permanent after saving. To “undo,” keep backups or version your files before making changes.

Q: Are all form field types supported? A: Yes! The Form Editor Plugin supports textboxes, checkboxes, comboboxes, radio buttons, and more as documented in the API.


Pro Tip: Use batch operations and advanced options to automate large-scale PDF form deployments with full control over field properties and placement.

 English