forms

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package forms provides AcroForm support for creating and filling interactive PDF form fields (ISO 32000 §12.7).

Supported field types:

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

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) Add

func (af *AcroForm) Add(f *Field) *AcroForm

Add appends a field to the form and returns the AcroForm for chaining.

func (*AcroForm) Build

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.

func (*AcroForm) Fields

func (af *AcroForm) Fields() []*Field

Fields returns all fields in the form.

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

func NewCheckbox(name string, rect [4]float64, pageIndex int, checked bool) *Field

NewCheckbox creates a checkbox field.

func NewDropdown added in v0.6.0

func NewDropdown(name string, rect [4]float64, pageIndex int, options []string) *Field

NewDropdown creates a dropdown (combo box) field.

func NewListBox added in v0.6.0

func NewListBox(name string, rect [4]float64, pageIndex int, options []string) *Field

NewListBox creates a list box field.

func NewMultilineTextField added in v0.6.0

func NewMultilineTextField(name string, rect [4]float64, pageIndex int) *Field

NewMultilineTextField creates a multi-line text area.

func NewPasswordField added in v0.6.0

func NewPasswordField(name string, rect [4]float64, pageIndex int) *Field

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

func NewSignatureField(name string, rect [4]float64, pageIndex int) *Field

NewSignatureField creates a digital signature field.

func NewTextField added in v0.6.0

func NewTextField(name string, rect [4]float64, pageIndex int) *Field

NewTextField creates a text input field.

func (*Field) SetBackgroundColor

func (f *Field) SetBackgroundColor(r, g, b float64) *Field

SetBackgroundColor sets the field's background color.

func (*Field) SetBorderColor

func (f *Field) SetBorderColor(r, g, b float64) *Field

SetBorderColor sets the field's border color.

func (*Field) SetReadOnly

func (f *Field) SetReadOnly() *Field

SetReadOnly marks the field as read-only.

func (*Field) SetRequired

func (f *Field) SetRequired() *Field

SetRequired marks the field as required.

func (*Field) SetValue

func (f *Field) SetValue(v string) *Field

SetValue sets the field's value.

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 FieldType

type FieldType int

FieldType identifies the kind of form field.

const (
	FieldText       FieldType = iota // text input
	FieldCheckbox                    // checkbox (on/off)
	FieldRadio                       // radio button group
	FieldDropdown                    // combo box / dropdown
	FieldListBox                     // list box (multi-select)
	FieldPushButton                  // push button
	FieldSignature                   // digital signature
)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL