Documentation
¶
Overview ¶
Package forms provides AcroForm support for creating and filling interactive PDF form fields (ISO 32000 §12.7).
Supported field types:
- Text input — NewTextField, NewMultilineTextField, NewPasswordField
- Selection — NewCheckbox, NewRadioGroup, NewDropdown, NewListBox
- Action — PushButton (via Field with FieldPushButton type)
- Signature — NewSignatureField
Each factory function returns a Field that can be configured with flags (ReadOnly, Required, etc.) and appearance properties. Call Field.ToDict to produce the PDF dictionary and widget annotations for embedding in a document.
Package forms provides AcroForm support for creating interactive PDF form fields: text inputs, checkboxes, radio buttons, dropdowns, and signature fields.
Index ¶
- type AcroForm
- type Field
- func NewCheckbox(name string, rect [4]float64, pageIndex int, checked bool) *Field
- func NewDropdown(name string, rect [4]float64, pageIndex int, options []string) *Field
- func NewListBox(name string, rect [4]float64, pageIndex int, options []string) *Field
- func NewMultilineTextField(name string, rect [4]float64, pageIndex int) *Field
- func NewPasswordField(name string, rect [4]float64, pageIndex int) *Field
- func NewRadioGroup(name string, options []RadioOption) *Field
- func NewSignatureField(name string, rect [4]float64, pageIndex int) *Field
- func NewTextField(name string, rect [4]float64, pageIndex int) *Field
- func (f *Field) SetBackgroundColor(r, g, b float64) *Field
- func (f *Field) SetBorderColor(r, g, b float64) *Field
- func (f *Field) SetReadOnly() *Field
- func (f *Field) SetRequired() *Field
- func (f *Field) SetValue(v string) *Field
- func (f *Field) ToDict(addObject func(core.PdfObject) *core.PdfIndirectReference, ...) (*core.PdfIndirectReference, []*widgetInfo)
- type FieldFlags
- type FieldType
- type FormFiller
- type RadioOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AcroForm ¶
type AcroForm struct {
// contains filtered or unexported fields
}
AcroForm manages the interactive form fields for a PDF document.
func NewAcroForm ¶
func NewAcroForm() *AcroForm
NewAcroForm creates an empty AcroForm with no fields.
func (*AcroForm) Build ¶
func (af *AcroForm) Build( addObject func(core.PdfObject) *core.PdfIndirectReference, pageRefs []*core.PdfIndirectReference, ) (*core.PdfIndirectReference, map[int][]*core.PdfIndirectReference)
Build creates the /AcroForm dictionary and all field/widget objects. It returns the AcroForm indirect reference and a map from page index to widget references, so the document layer can add them to each page's /Annots array.
type Field ¶
type Field struct {
Name string // /T — field name (required)
Type FieldType // determines /FT
Value string // /V — current value
Default string // /DV — default value
Flags FieldFlags // /Ff — field flags
Rect [4]float64 // widget annotation rectangle [x1, y1, x2, y2]
PageIndex int // which page this field is on (0-based)
// Appearance properties.
FontSize float64 // 0 = auto-size
FontName string // default: "Helv" (Helvetica)
TextColor [3]float64 // RGB [0-1], default black
BGColor *[3]float64 // background color (nil = transparent)
BorderColor *[3]float64 // border color (nil = no border)
BorderWidth float64 // default 1
// Choice field options.
Options []string // for dropdown/listbox
// Radio/checkbox.
ExportValue string // /AS or /V value when checked (default "Yes")
// contains filtered or unexported fields
}
Field represents a single form field.
func NewCheckbox ¶ added in v0.6.0
NewCheckbox creates a checkbox field.
func NewDropdown ¶ added in v0.6.0
NewDropdown creates a dropdown (combo box) field.
func NewListBox ¶ added in v0.6.0
NewListBox creates a list box field.
func NewMultilineTextField ¶ added in v0.6.0
NewMultilineTextField creates a multi-line text area.
func NewPasswordField ¶ added in v0.6.0
NewPasswordField creates a password input field.
func NewRadioGroup ¶ added in v0.6.0
func NewRadioGroup(name string, options []RadioOption) *Field
NewRadioGroup creates a radio button group with the given options. Each RadioOption becomes a child widget field representing one button.
func NewSignatureField ¶ added in v0.6.0
NewSignatureField creates a digital signature field.
func NewTextField ¶ added in v0.6.0
NewTextField creates a text input field.
func (*Field) SetBackgroundColor ¶
SetBackgroundColor sets the field's background color.
func (*Field) SetBorderColor ¶
SetBorderColor sets the field's border color.
func (*Field) SetReadOnly ¶
SetReadOnly marks the field as read-only.
func (*Field) SetRequired ¶
SetRequired marks the field as required.
func (*Field) ToDict ¶
func (f *Field) ToDict(addObject func(core.PdfObject) *core.PdfIndirectReference, pageRefs []*core.PdfIndirectReference) (*core.PdfIndirectReference, []*widgetInfo)
ToDict converts the field to a PDF dictionary and registers it via addObject. It returns the field's indirect reference and widget info for page annotation placement.
type FieldFlags ¶
type FieldFlags uint32
FieldFlags are bit flags for form field properties (ISO 32000 §12.7.3).
const ( FlagReadOnly FieldFlags = 1 << 0 // field cannot be edited FlagRequired FieldFlags = 1 << 1 // field must have a value FlagNoExport FieldFlags = 1 << 2 // field excluded from export // Text field specific flags. FlagMultiline FieldFlags = 1 << 12 // multi-line text FlagPassword FieldFlags = 1 << 13 // password (hidden chars) FlagFileSelect FieldFlags = 1 << 20 // file path input FlagDoNotSpellCheck FieldFlags = 1 << 22 // disable spell check FlagDoNotScroll FieldFlags = 1 << 23 // disable scrolling for long text FlagComb FieldFlags = 1 << 24 // evenly spaced characters FlagRichText FieldFlags = 1 << 25 // rich text value // Choice field specific flags. FlagCombo FieldFlags = 1 << 17 // combo box (dropdown) vs list box FlagEdit FieldFlags = 1 << 18 // editable combo box FlagSort FieldFlags = 1 << 19 // sorted options FlagMultiSelect FieldFlags = 1 << 21 // allow multiple selections // Button specific flags. FlagNoToggleToOff FieldFlags = 1 << 14 // one radio button must always be selected FlagRadioFlag FieldFlags = 1 << 15 // radio button (vs checkbox) FlagPushButtonFlag FieldFlags = 1 << 16 // push button (no persistent value) )
type FormFiller ¶
type FormFiller struct {
// contains filtered or unexported fields
}
FormFiller reads form fields from an existing PDF and allows modifying their values before saving.
func NewFormFiller ¶
func NewFormFiller(r *reader.PdfReader) *FormFiller
NewFormFiller creates a filler from a parsed PDF.
func (*FormFiller) FieldNames ¶
func (ff *FormFiller) FieldNames() ([]string, error)
FieldNames returns the names of all form fields in the document.
func (*FormFiller) GetValue ¶
func (ff *FormFiller) GetValue(fieldName string) (string, error)
GetValue returns the current value of a form field.
func (*FormFiller) SetCheckbox ¶
func (ff *FormFiller) SetCheckbox(fieldName string, checked bool) error
SetCheckbox sets a checkbox field's value. checked=true sets it to the export value, false sets to "Off".
func (*FormFiller) SetValue ¶
func (ff *FormFiller) SetValue(fieldName, value string) error
SetValue sets the value of a form field. The change is applied to the in-memory PDF objects. To persist the change, pass the reader to reader.Merge and call SaveTo or WriteTo on the result.
type RadioOption ¶
type RadioOption struct {
Value string // export value when selected
Rect [4]float64 // position on page
PageIndex int // zero-based page index
}
RadioOption defines one button in a radio group.