Fill AcroForm - Fill PDF Form using C#

The following code snippet also work with Aspose.PDF.Drawing library.

Fill Form Field in a PDF Document

To fill a form field, get the field from the Document object’s Form collection. then set the field value using the field’s Value property.

This example selects a TextBoxField and sets its value using the Value property.

// For complete examples and data files, please go to https://github.com/aspose-pdf/Aspose.PDF-for-.NET

private static void FillFormField()
{
    // The path to the documents directory
    string dataDir = RunExamples.GetDataDir_AsposePdf_Forms();

    // Open document
    using (var document = new Aspose.Pdf.Document(dataDir + "FillFormField.pdf"))
	{
		// Get a field
		if (document.Form["textbox1"] is Aspose.Pdf.Forms.TextBoxField textBoxField)
		{
			// Modify field value
			textBoxField.Value = "Value to be filled in the field";
		}

		// Save updated document
		document.Save(dataDir + "FillFormField_out.pdf");
	}
}