acroform

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package acroform provides action support for form fields

Package acroform provides appearance stream creation for form fields

Package acroform provides AcroForm extraction functions

Package acroform provides AcroForm field filling functionality

Package acroform provides form filling with object stream support

Package acroform provides form flattening functionality

Package acroform provides integration with SimplePDFBuilder

Package acroform provides AcroForm (standard PDF form) parsing and manipulation

Package acroform provides object replacement for form filling

Package acroform provides utilities to find object streams

Package acroform provides object stream rebuilding for form filling

Package acroform provides AcroForm field validation

Package acroform provides AcroForm creation and writing functionality

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddAcroFormToCatalog

func AddAcroFormToCatalog(w *write.PDFWriter, catalogNum, acroFormNum int) error

AddAcroFormToCatalog adds AcroForm reference to catalog

func AddActionToField

func AddActionToField(fieldObjNum int, action *Action, w *write.PDFWriter) error

AddActionToField adds an action to a field

func AddAppearanceToField

func AddAppearanceToField(fieldObjNum, appearanceNum int, w *write.PDFWriter) error

AddAppearanceToField adds an appearance stream to a field object

func AddMouseAction

func AddMouseAction(fieldObjNum int, event string, action *Action, w *write.PDFWriter) error

AddMouseAction adds a mouse-triggered action (e.g., onClick)

func ExtractAndFill

func ExtractAndFill(pdfBytes []byte, formData types.FormData, password []byte, verbose bool) ([]byte, error)

ExtractAndFill extracts AcroForm, validates, and fills

func ExtractFormSchema

func ExtractFormSchema(pdfBytes []byte, password []byte, verbose bool) (*types.FormSchema, error)

ExtractFormSchema extracts AcroForm and converts it to FormSchema

func FillFieldValue

func FillFieldValue(pdfBytes []byte, field *Field, value interface{}, encryptInfo *types.PDFEncryption, verbose bool) ([]byte, error)

FillFieldValue fills a field with a value by replacing the object

func FillForm

func FillForm(pdfBytes []byte, formData types.FormData, password []byte, verbose bool) ([]byte, error)

FillForm fills AcroForm fields with values from FormData Returns modified PDF bytes This is a convenience wrapper around FillFormFields

func FillFormFields

func FillFormFields(pdfBytes []byte, formData types.FormData, password []byte, verbose bool) ([]byte, error)

FillFormFields fills multiple fields in a PDF This function attempts to handle both direct objects and object streams

func FillFormFieldsWithStreams

func FillFormFieldsWithStreams(pdfBytes []byte, formData types.FormData, password []byte, verbose bool) ([]byte, error)

FillFormFieldsWithStreams fills form fields, handling both direct objects and object streams

func FillFormFromSchema

func FillFormFromSchema(pdfBytes []byte, schema *types.FormSchema, formData types.FormData, password []byte, verbose bool) ([]byte, error)

FillFormFromSchema fills a form from FormSchema and FormData

func FlattenField

func FlattenField(pdfBytes []byte, field *Field, encryptInfo *types.PDFEncryption, verbose bool) ([]byte, error)

FlattenField converts a single field to static content

func FlattenForm

func FlattenForm(pdfBytes []byte, password []byte, verbose bool) ([]byte, error)

FlattenForm converts form fields to static content (removes interactivity) This creates a new PDF with form fields rendered as regular text/graphics

func GetFieldAppearance

func GetFieldAppearance(field *Field, pdfBytes []byte, encryptInfo *types.PDFEncryption, verbose bool) ([]byte, error)

GetFieldAppearance gets the appearance stream for a field

func RebuildObjectStream

func RebuildObjectStream(pdfBytes []byte, streamObjNum int, updates []StreamObjectUpdate, encryptInfo *types.PDFEncryption, verbose bool) ([]byte, error)

RebuildObjectStream rebuilds an object stream with updated objects

func ReplaceFieldObject

func ReplaceFieldObject(pdfBytes []byte, objNum, genNum int, newContent []byte, encryptInfo *types.PDFEncryption, verbose bool) ([]byte, error)

ReplaceFieldObject replaces a field object in a PDF

func ValidateField

func ValidateField(field *Field, value interface{}) error

ValidateField validates a single field value against its constraints

func ValidateFieldValue

func ValidateFieldValue(question *types.Question, value interface{}) error

ValidateFieldValue validates a field value using FormSchema validation rules

func ValidateFormData

func ValidateFormData(acroForm *AcroForm, formData types.FormData) []error

ValidateFormData validates all fields in form data against the AcroForm

func ValidateFormSchema

func ValidateFormSchema(schema *types.FormSchema, formData types.FormData) []error

ValidateFormSchema validates form data against a FormSchema

Types

type AcroForm

type AcroForm struct {
	Fields          []*Field
	NeedAppearances bool
	SignatureFields []int // Object numbers of signature fields
	XFA             bool  // True if XFA is present (hybrid form)
}

AcroForm represents an AcroForm dictionary structure

func ExtractAcroForm

func ExtractAcroForm(pdfBytes []byte, password []byte, verbose bool) (*AcroForm, error)

ExtractAcroForm extracts AcroForm structure from a PDF This is the main entry point for AcroForm extraction

func ParseAcroForm

func ParseAcroForm(pdfBytes []byte, encryptInfo *types.PDFEncryption, verbose bool) (*AcroForm, error)

ParseAcroForm extracts AcroForm structure from a PDF

func (*AcroForm) FindFieldByName

func (af *AcroForm) FindFieldByName(name string) *Field

FindFieldByName finds a field by its name

func (*AcroForm) GetFieldValues

func (af *AcroForm) GetFieldValues() map[string]interface{}

GetFieldValues extracts current values from all AcroForm fields

func (*AcroForm) ToFormSchema

func (af *AcroForm) ToFormSchema() *types.FormSchema

ToFormSchema converts AcroForm to FormSchema

type Action

type Action struct {
	Type        ActionType
	URI         string // For URI actions
	JavaScript  string // For JavaScript actions
	Destination string // For GoTo actions (e.g., "1 0 R" or page number)
	PageNum     int    // For GoTo actions (page number)
}

Action represents a PDF action

type ActionType

type ActionType string

ActionType represents the type of PDF action

const (
	ActionTypeGoTo       ActionType = "GoTo"       // Navigate to a page/destination
	ActionTypeURI        ActionType = "URI"        // Open a URI
	ActionTypeJavaScript ActionType = "JavaScript" // Execute JavaScript
	ActionTypeSubmit     ActionType = "SubmitForm" // Submit form
	ActionTypeReset      ActionType = "ResetForm"  // Reset form
)

type AppearanceBuilder

type AppearanceBuilder struct {
	// contains filtered or unexported fields
}

AppearanceBuilder helps create appearance streams for form fields

func NewAppearanceBuilder

func NewAppearanceBuilder(w *write.PDFWriter) *AppearanceBuilder

NewAppearanceBuilder creates a new appearance builder

func (*AppearanceBuilder) CreateButtonAppearance

func (ab *AppearanceBuilder) CreateButtonAppearance(label string, width, height, fontSize float64) (int, error)

CreateButtonAppearance creates an appearance stream for a button

func (*AppearanceBuilder) CreateCheckboxAppearance

func (ab *AppearanceBuilder) CreateCheckboxAppearance(checked bool, width, height float64) (int, error)

CreateCheckboxAppearance creates an appearance stream for a checkbox

func (*AppearanceBuilder) CreateTextAppearance

func (ab *AppearanceBuilder) CreateTextAppearance(text string, width, height, fontSize float64, fontName string) (int, error)

CreateTextAppearance creates an appearance stream for a text field

type Field

type Field struct {
	ObjectNum  int
	Generation int
	FT         string                 // Field type: Tx (text), Btn (button), Ch (choice), Sig (signature)
	Parent     *Field                 // Parent field (for fields in a hierarchy)
	Kids       []*Field               // Child fields
	T          string                 // Field name (partial name)
	TU         string                 // Alternate field name
	TM         string                 // Mapping name
	Ff         int                    // Field flags
	V          interface{}            // Field value
	DV         interface{}            // Default value
	AA         map[string]interface{} // Additional actions
	DA         string                 // Default appearance string
	Q          int                    // Quadding (justification)
	MaxLen     int                    // Maximum length (for text fields)
	Opt        []interface{}          // Options (for choice fields)
	TI         int                    // Top index (for choice fields)
	I          []int                  // Selected indices (for choice fields)
	Rect       []float64              // Field rectangle [llx lly urx ury]
	Page       int                    // Page number (0-indexed)
}

Field represents a single AcroForm field

func (*Field) GetFullName

func (f *Field) GetFullName() string

GetFullName returns the full field name (handles hierarchical names)

func (*Field) ToQuestion

func (f *Field) ToQuestion() *types.Question

ToQuestion converts a Field to a Question

type FieldBuilder

type FieldBuilder struct {
	// contains filtered or unexported fields
}

FieldBuilder helps build AcroForm fields

func NewFieldBuilder

func NewFieldBuilder(w *write.PDFWriter) *FieldBuilder

NewFieldBuilder creates a new field builder

func (*FieldBuilder) AddButton

func (fb *FieldBuilder) AddButton(name string, rect []float64, page int) *FieldDef

AddButton adds a push button

func (*FieldBuilder) AddCheckbox

func (fb *FieldBuilder) AddCheckbox(name string, rect []float64, page int) *FieldDef

AddCheckbox adds a checkbox field

func (*FieldBuilder) AddChoiceField

func (fb *FieldBuilder) AddChoiceField(name string, rect []float64, page int, options []string) *FieldDef

AddChoiceField adds a choice (dropdown/list) field

func (*FieldBuilder) AddRadioButton

func (fb *FieldBuilder) AddRadioButton(name string, rect []float64, page int) *FieldDef

AddRadioButton adds a radio button field

func (*FieldBuilder) AddTextField

func (fb *FieldBuilder) AddTextField(name string, rect []float64, page int) *FieldDef

AddTextField adds a text field to the form

func (*FieldBuilder) Build

func (fb *FieldBuilder) Build() (int, error)

Build creates the AcroForm dictionary and field objects

type FieldDef

type FieldDef struct {
	Name         string
	Type         string // Tx, Btn, Ch, Sig
	Value        interface{}
	DefaultValue interface{}
	Rect         []float64 // [llx lly urx ury]
	Page         int
	Flags        int
	Options      []string // For choice fields
	MaxLen       int      // For text fields
	Required     bool
	ReadOnly     bool
}

FieldDef represents a field definition for creation

func (*FieldDef) SetDefault

func (fd *FieldDef) SetDefault(value interface{}) *FieldDef

SetDefault sets the default value

func (*FieldDef) SetMaxLength

func (fd *FieldDef) SetMaxLength(maxLen int) *FieldDef

SetMaxLength sets maximum length for text fields

func (*FieldDef) SetReadOnly

func (fd *FieldDef) SetReadOnly(readonly bool) *FieldDef

SetReadOnly marks the field as read-only

func (*FieldDef) SetRequired

func (fd *FieldDef) SetRequired(required bool) *FieldDef

SetRequired marks the field as required

func (*FieldDef) SetValue

func (fd *FieldDef) SetValue(value interface{}) *FieldDef

SetValue sets the field value

type FormBuilder

type FormBuilder struct {
	// contains filtered or unexported fields
}

FormBuilder integrates AcroForm creation with SimplePDFBuilder

func NewFormBuilder

func NewFormBuilder(builder *write.SimplePDFBuilder) *FormBuilder

NewFormBuilder creates a new form builder integrated with SimplePDFBuilder

func (*FormBuilder) AddButton

func (fb *FormBuilder) AddButton(name string, rect []float64, page int) *FieldDef

AddButton adds a push button

func (*FormBuilder) AddCheckbox

func (fb *FormBuilder) AddCheckbox(name string, rect []float64, page int) *FieldDef

AddCheckbox adds a checkbox field

func (*FormBuilder) AddChoiceField

func (fb *FormBuilder) AddChoiceField(name string, rect []float64, page int, options []string) *FieldDef

AddChoiceField adds a choice (dropdown/list) field

func (*FormBuilder) AddRadioButton

func (fb *FormBuilder) AddRadioButton(name string, rect []float64, page int) *FieldDef

AddRadioButton adds a radio button field

func (*FormBuilder) AddTextField

func (fb *FormBuilder) AddTextField(name string, rect []float64, page int) *FieldDef

AddTextField adds a text field to the form

func (*FormBuilder) BuildForm

func (fb *FormBuilder) BuildForm() (int, error)

BuildForm builds the AcroForm and integrates it with the PDF

type StreamObjectUpdate

type StreamObjectUpdate struct {
	ObjNum     int
	Index      int
	NewContent []byte
}

StreamObjectUpdate tracks updates to objects in a stream

type ValidationError

type ValidationError struct {
	FieldName string
	Message   string
	Value     interface{}
}

ValidationError represents a validation error for a field

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

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