---
Product: Aspose.PDF
Platform: go
Page Type: reference
Canonical URL: https://reference.aspose.org/pdf/go/form
---

# Form

## Overview

`Form` is a type in Aspose.PDF FOSS for Go.

Form is the document's AcroForm view.

This type declares 30 methods for Form objects in Go programs.
Available methods include: `AddCheckbox`, `AddComboBox`, `AddDateField`, `AddFileSelectField`, `AddListBox`, `AddNumberField`, `AddPasswordField`, `AddPushButton`, `AddRadioGroup`, `AddRichTextField`, `AddTextField`, `ExportFDF`, and 18 additional methods.
Public members are accessible to any Go application after installing the Aspose.PDF FOSS for Go package.

## Methods

| Signature | Description |
|-----------|-------------|
| `Flatten()` → `error` | Flatten bakes every form field's current appearance into its page's content stream and then removes all fields, their widgets, and the /AcroForm dict, producing a non-interactive document that renders the same. |
| `Fields()` → `[]Field` | Fields returns all leaf form fields as a flat slice. |
| `Field(name: string)` → `Field` | Field returns the leaf field by FullName, or nil if no such field exists. |
| `HasField(name: string)` → `bool` | HasField reports whether a leaf field with the given FullName exists. |
| `NeedAppearances()` → `bool` | NeedAppearances reports whether /AcroForm/NeedAppearances is true, which tells viewers to regenerate cached /AP appearance streams when displaying form fields. |
| `SetNeedAppearances(v: bool)` | SetNeedAppearances toggles /AcroForm/NeedAppearances. |
| `AddTextField(pageNum: int, rect: Rectangle, name: string)` → `(*TextBoxField, error)` | AddTextField creates a single-line text input on pageNum with the given rectangle and field name, auto-creating /AcroForm and the default Helvetica font resource if needed. |
| `AddCheckbox(pageNum: int, rect: Rectangle, name: string)` → `(*CheckboxField, error)` | AddCheckbox creates a checkbox widget on pageNum with the given rectangle and field name. |
| `AddComboBox(pageNum: int, rect: Rectangle, name: string, options: []ChoiceOption)` → `(*ComboBoxField, error)` | AddComboBox creates a single-select dropdown choice field. |
| `AddListBox(pageNum: int, rect: Rectangle, name: string, options: []ChoiceOption)` → `(*ListBoxField, error)` | AddListBox creates a single-select list field. |
| `AddPushButton(pageNum: int, rect: Rectangle, name: string, caption: string)` → `(*ButtonField, error)` | AddPushButton creates a non-toggling button. |
| `AddRadioGroup(name: string, items: []RadioItem)` → `(*RadioButtonField, error)` | AddRadioGroup creates a radio-button parent field plus one widget per item. |
| `RemoveField(name: string)` → `bool` | RemoveField removes the named field (and all its widget annotations) from /AcroForm/Fields and from each affected page's /Annots. |
| `ExportFDF()` → `([]byte, error)` | ExportFDF serialises the form's field values as an FDF (Forms Data Format) document — a small PDF-syntax file (`%FDF-1.2` … `/FDF /Fields [ … ]`) that Acrobat and other readers import. |
| `WriteFDF(w: io.Writer)` → `error` | WriteFDF writes ExportFDF output to w. |
| `ImportFDF(data: []byte)` → `(int, error)` | ImportFDF applies field values from an FDF document and returns the number of fields set. |
| `ReadFDF(r: io.Reader)` → `(int, error)` | ReadFDF reads an FDF document from r and applies it via ImportFDF. |
| `AddPasswordField(pageNum: int, rect: Rectangle, name: string)` → `(*PasswordBoxField, error)` | AddPasswordField adds a masked text field. |
| `AddFileSelectField(pageNum: int, rect: Rectangle, name: string)` → `(*FileSelectBoxField, error)` | AddFileSelectField adds a file-select text field. |
| `AddRichTextField(pageNum: int, rect: Rectangle, name: string)` → `(*RichTextBoxField, error)` | AddRichTextField adds a rich-text field. |
| `AddNumberField(pageNum: int, rect: Rectangle, name: string, opts: NumberFormatOptions)` → `(*NumberField, error)` | AddNumberField adds a number field formatted per opts. |
| `AddDateField(pageNum: int, rect: Rectangle, name: string, format: string)` → `(*DateField, error)` | AddDateField adds a date field with the given format mask (e.g. |
| `ExportJSON(opts: ...JSONExportOptions)` → `([]byte, error)` | ExportJSON serialises the form's field values to a typed JSON document keyed by each field's full name: `{"name": {"type": "...", "value": ...}}`. |
| `WriteJSON(w: io.Writer, opts: ...JSONExportOptions)` → `error` | WriteJSON writes ExportJSON output to w. |
| `ImportJSON(data: []byte)` → `(int, error)` | ImportJSON applies field values from a typed JSON document (the shape ExportJSON produces) and returns the number of fields actually set. |
| `ReadJSON(r: io.Reader)` → `(int, error)` | ReadJSON reads a JSON document from r and applies it via ImportJSON. |
| `ExportXFDF()` → `([]byte, error)` | ExportXFDF serialises the form's field values as an XFDF document. |
| `WriteXFDF(w: io.Writer)` → `error` | WriteXFDF writes ExportXFDF output to w. |
| `ImportXFDF(data: []byte)` → `(int, error)` | ImportXFDF applies field values from an XFDF document and returns the number of fields set. |
| `ReadXFDF(r: io.Reader)` → `(int, error)` | ReadXFDF reads an XFDF document from r and applies it via ImportXFDF. |

## See Also

- [Aspose.PDF — Enterprise API Reference](https://reference.aspose.com/pdf/)