forms

package
v2.9.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package forms provides a unified interface for working with PDF forms It supports both AcroForm and XFA form types with automatic detection

Index

Constants

This section is empty.

Variables

View Source
var ErrCryptFilterDecodeParmsConflict = errors.New("stream dict has /Filter array with /Crypt plus other filters and an array-form /DecodeParms; dropping /Crypt would misalign /DecodeParms (not supported)")

ErrCryptFilterDecodeParmsConflict is returned by xfaStripCryptFilter when a stream dict contains both /Filter[/Crypt /Other...] and an array-form /DecodeParms entry. Per PDF 7.4.1 the two arrays are positionally aligned, so dropping /Crypt from /Filter would shift the parametrisation of every remaining filter by one — a bug we can't fix without also rewriting the /DecodeParms array. The eSTAR templates this code targets never combine /Crypt with other filters, so this case is unreachable in practice; we error rather than silently miscoding it for future inputs.

Functions

func ExtractAcroForm

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

ExtractAcroForm extracts an AcroForm (type-specific)

func ExtractXFA

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

ExtractXFA extracts XFA form data (type-specific) Returns the FormSchema and Datasets separately

Types

type AcroFormWrapper

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

AcroFormWrapper wraps an AcroForm to implement the Form interface

func (*AcroFormWrapper) Fill

func (w *AcroFormWrapper) Fill(pdfBytes []byte, data types.FormData, password []byte, verbose bool) ([]byte, error)

func (*AcroFormWrapper) GetValues

func (w *AcroFormWrapper) GetValues() map[string]interface{}

func (*AcroFormWrapper) Schema

func (w *AcroFormWrapper) Schema() *types.FormSchema

func (*AcroFormWrapper) Type

func (w *AcroFormWrapper) Type() FormType

func (*AcroFormWrapper) Validate

func (w *AcroFormWrapper) Validate(data types.FormData) []error

type FillOptions added in v2.7.0

type FillOptions struct {
	Strategy FillStrategy // default StrategyByteRewrite (current Fill behavior)
}

FillOptions configures XFAFormWrapper.FillWithOptions.

type FillStrategy added in v2.7.0

type FillStrategy int

FillStrategy selects how XFA form fills modify the PDF.

const (
	// StrategyByteRewrite patches the datasets stream in place, decrypting the
	// whole document first when the source is encrypted (output is plaintext).
	// Only works for classical-xref sources; xref-stream sources automatically
	// use the incremental path instead. That automatic routing means the
	// plaintext-output rule above holds only for classical-xref sources: an
	// encrypted xref-stream source filled with this (default) strategy goes
	// through the incremental path and produces encrypted output, same as
	// StrategyIncrementalUpdate.
	StrategyByteRewrite FillStrategy = iota
	// StrategyIncrementalUpdate appends a PDF incremental update (ISO 32000-1
	// §7.5.6): original bytes are preserved verbatim, the source's encryption
	// is preserved (the new datasets stream is re-encrypted with the document
	// key), and signatures over the original revision are not invalidated.
	StrategyIncrementalUpdate
)

type Form

type Form interface {
	// Type returns the form type (AcroForm or XFA)
	Type() FormType

	// Schema returns the form schema (structure and fields)
	Schema() *types.FormSchema

	// Fill fills the form with the provided data and returns modified PDF bytes
	Fill(pdfBytes []byte, data types.FormData, password []byte, verbose bool) ([]byte, error)

	// Validate validates form data against the form's validation rules
	Validate(data types.FormData) []error

	// GetValues returns the current values of all form fields
	GetValues() map[string]interface{}
}

Form represents a unified form interface

func Extract

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

Extract extracts and returns a unified Form interface It automatically detects whether the PDF contains AcroForm or XFA forms

type FormType

type FormType string

FormType represents the type of form

const (
	FormTypeAcroForm FormType = "acroform"
	FormTypeXFA      FormType = "xfa"
	FormTypeUnknown  FormType = "unknown"
)

func Detect

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

Detect detects the form type in a PDF

type XFAFormWrapper

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

XFAFormWrapper wraps XFA form data to implement the Form interface

func (*XFAFormWrapper) Fill

func (w *XFAFormWrapper) Fill(pdfBytes []byte, data types.FormData, password []byte, verbose bool) ([]byte, error)

func (*XFAFormWrapper) FillWithOptions added in v2.7.0

func (w *XFAFormWrapper) FillWithOptions(pdfBytes []byte, data types.FormData, password []byte, opts FillOptions, verbose bool) ([]byte, error)

FillWithOptions fills the form like Fill, with an explicit strategy choice. StrategyIncrementalUpdate works directly on the supplied (possibly encrypted) bytes and preserves the source's encryption in the output, unlike the default path which returns plaintext for encrypted sources.

func (*XFAFormWrapper) GetValues

func (w *XFAFormWrapper) GetValues() map[string]interface{}

func (*XFAFormWrapper) Schema

func (w *XFAFormWrapper) Schema() *types.FormSchema

func (*XFAFormWrapper) Type

func (w *XFAFormWrapper) Type() FormType

func (*XFAFormWrapper) Validate

func (w *XFAFormWrapper) Validate(data types.FormData) []error

Directories

Path Synopsis
Package acroform provides action support for form fields
Package acroform provides action support for form fields

Jump to

Keyboard shortcuts

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