Documents for PDF .NET Edition
Features / Forms
In This Topic
    In This Topic

    The PDF-based fillable form, also known as AcroForm, is an interactive form with a collection of fields, such as TextBox, Button, CheckBox, etc. These fields can be filled with data programmatically or manually in order to take information as input from the user. For more information on AcroForm, see PDF specification 1.7 (Section 12.7).

    GcPdf allows you to create AcroForms using AcroForm class and define common properties of AcroForm using Fields property of AcroForm class. The library lets you add, get, modify, and delete different form fields. You can use the following fields in AcroForms.


    Add AcroForm Fields

    To add AcroForm fields in a PDF document using GcPdf:

    1. Create an instance of class corresponding to field you want to add to the form, for example,
      TextField class.
    2. Set the basic properties of the field.
      Observe that the field is also being filled in the code through Value property.
    3. Add the field to the form using the Add method.
      Copy Code
      public void CreatePDF(Stream stream)
          var doc = new GcPdfDocument();
          var page = doc.NewPage();
          var g = page.Graphics;
          TextFormat tf = new TextFormat();
          tf.Font = StandardFonts.Times;
          tf.FontSize = 14;
          PointF ip = new PointF(72, 72);
          float fldOffset = 72 * 2;
          float fldHeight = tf.FontSize * 1.2f;
          float dY = 32;
          // Add TextField
          g.DrawString("Text field:", tf, ip);
          var fldText = new TextField();
          fldText.Value = "Initial TextField value";
          fldText.Widget.Page = page;
          fldText.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight);
          fldText.Widget.TextFormat.Font = tf.Font;
          fldText.Widget.TextFormat.FontSize = tf.FontSize;
          ip.Y += dY;
          // Add Checkbox:
          g.DrawString("Checkbox:", tf, ip);
          var fldCheckbox = new CheckBoxField();
          fldCheckbox.Value = true;
          fldCheckbox.Widget.Page = page;
          fldCheckbox.Widget.Rect = new RectangleF(ip.X + fldOffset, ip.Y, fldHeight, fldHeight);
          ip.Y += dY;
          // Save Document
    Back to Top

    Modify AcroForm Fields

    To modify form fields in PDF document, get the particular form field by specifying its index and set a new value for the field using Value property. This property fills the field with the specified string value.

    Copy Code
    doc.AcroForm.Fields[0].Value = "Sample Text";
    Back to Top

    Delete AcroForm Fields

    To delete a particular form field in PDF document, use RemoveAt method to remove any field by specifying its index value. Apart from this, Clear method can be used to remove all the AcroForm fields from the document.

    Copy Code
    // Delete a particular field
    // Delete all the fields
    Back to Top

    For more information about implementation of AcroForms using GcPdf, see GcPdf sample browser.