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 ¶
- func AddAcroFormToCatalog(w *write.PDFWriter, catalogNum, acroFormNum int) error
- func AddActionToField(fieldObjNum int, action *Action, w *write.PDFWriter) error
- func AddAppearanceToField(fieldObjNum, appearanceNum int, w *write.PDFWriter) error
- func AddMouseAction(fieldObjNum int, event string, action *Action, w *write.PDFWriter) error
- func ExtractAndFill(pdfBytes []byte, formData types.FormData, password []byte, verbose bool) ([]byte, error)
- func ExtractFormSchema(pdfBytes []byte, password []byte, verbose bool) (*types.FormSchema, error)
- func FillFieldValue(pdfBytes []byte, field *Field, value interface{}, ...) ([]byte, error)
- func FillForm(pdfBytes []byte, formData types.FormData, password []byte, verbose bool) ([]byte, error)
- func FillFormFields(pdfBytes []byte, formData types.FormData, password []byte, verbose bool) ([]byte, error)
- func FillFormFieldsWithStreams(pdfBytes []byte, formData types.FormData, password []byte, verbose bool) ([]byte, error)
- func FillFormFromSchema(pdfBytes []byte, schema *types.FormSchema, formData types.FormData, ...) ([]byte, error)
- func FlattenField(pdfBytes []byte, field *Field, encryptInfo *types.PDFEncryption, verbose bool) ([]byte, error)
- func FlattenForm(pdfBytes []byte, password []byte, verbose bool) ([]byte, error)
- func GetFieldAppearance(field *Field, pdfBytes []byte, encryptInfo *types.PDFEncryption, verbose bool) ([]byte, error)
- func RebuildObjectStream(pdfBytes []byte, streamObjNum int, updates []StreamObjectUpdate, ...) ([]byte, error)
- func ReplaceFieldObject(pdfBytes []byte, objNum, genNum int, newContent []byte, ...) ([]byte, error)
- func ValidateField(field *Field, value interface{}) error
- func ValidateFieldValue(question *types.Question, value interface{}) error
- func ValidateFormData(acroForm *AcroForm, formData types.FormData) []error
- func ValidateFormSchema(schema *types.FormSchema, formData types.FormData) []error
- type AcroForm
- type Action
- type ActionType
- type AppearanceBuilder
- func (ab *AppearanceBuilder) CreateButtonAppearance(label string, width, height, fontSize float64) (int, error)
- func (ab *AppearanceBuilder) CreateCheckboxAppearance(checked bool, width, height float64) (int, error)
- func (ab *AppearanceBuilder) CreateTextAppearance(text string, width, height, fontSize float64, fontName string) (int, error)
- type Field
- type FieldBuilder
- func (fb *FieldBuilder) AddButton(name string, rect []float64, page int) *FieldDef
- func (fb *FieldBuilder) AddCheckbox(name string, rect []float64, page int) *FieldDef
- func (fb *FieldBuilder) AddChoiceField(name string, rect []float64, page int, options []string) *FieldDef
- func (fb *FieldBuilder) AddRadioButton(name string, rect []float64, page int) *FieldDef
- func (fb *FieldBuilder) AddTextField(name string, rect []float64, page int) *FieldDef
- func (fb *FieldBuilder) Build() (int, error)
- type FieldDef
- type FormBuilder
- func (fb *FormBuilder) AddButton(name string, rect []float64, page int) *FieldDef
- func (fb *FormBuilder) AddCheckbox(name string, rect []float64, page int) *FieldDef
- func (fb *FormBuilder) AddChoiceField(name string, rect []float64, page int, options []string) *FieldDef
- func (fb *FormBuilder) AddRadioButton(name string, rect []float64, page int) *FieldDef
- func (fb *FormBuilder) AddTextField(name string, rect []float64, page int) *FieldDef
- func (fb *FormBuilder) BuildForm() (int, error)
- type StreamObjectUpdate
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddAcroFormToCatalog ¶
AddAcroFormToCatalog adds AcroForm reference to catalog
func AddActionToField ¶
AddActionToField adds an action to a field
func AddAppearanceToField ¶
AddAppearanceToField adds an appearance stream to a field object
func AddMouseAction ¶
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 ¶
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 ¶
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 ¶
ValidateField validates a single field value against its constraints
func ValidateFieldValue ¶
ValidateFieldValue validates a field value using FormSchema validation rules
func ValidateFormData ¶
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 ¶
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 ¶
FindFieldByName finds a field by its name
func (*AcroForm) GetFieldValues ¶
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 ¶
GetFullName returns the full field name (handles hierarchical names)
func (*Field) ToQuestion ¶
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 ¶
SetDefault sets the default value
func (*FieldDef) SetMaxLength ¶
SetMaxLength sets maximum length for text fields
func (*FieldDef) SetReadOnly ¶
SetReadOnly marks the field as read-only
func (*FieldDef) SetRequired ¶
SetRequired marks the field as required
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 ¶
StreamObjectUpdate tracks updates to objects in a stream
type ValidationError ¶
ValidationError represents a validation error for a field
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string