Advanced AcroForm Processing
HotPDF can recalculate loaded fields, regenerate standards-based variable-text appearances, resolve annotation appearance states, and flatten a selected field set without rewriting untouched pages
Calculation order
RecalculateLoadedFormFields follows the loaded /AcroForm /CO array and evaluates the bounded AFSimple_Calculate operations SUM, AVG, PRD, MIN, and MAX through the safe field-script evaluator
ApplyLoadedFieldCalculation installs the calculation action and adds the target field to /CO without duplicate entries
Safe field scripts
EvaluateLoadedFieldJavaScript evaluates only declarative calculation and validation statements associated with the requested field trigger
- Expressions support boolean, number, string, null, undefined, and array values with arithmetic, unary, comparison, equality, short-circuit logical, and conditional operators
event.valuepreserves string input semantics, while numeric field text remains numeric for compatibility with existing calculations- Allowlisted helpers cover number and string conversion, parsing, selected
Mathfunctions, deterministic UTC date parsing and construction, and bounded string and array inspection AFSimple_Calculate,AFRange_Validate,event.valueassignment, andevent.rcassignment provide deterministic calculation and validation outcomes- Loops, dynamic evaluation, application access, submission, import, launch, and other active content are rejected
- Limits are 8,192 script bytes, 32 statements, 4,096 expression bytes, 32 parser levels, 1,024 operations, 64 arguments, 128 array items, 65,536 string bytes, and 262,144 bytes of tracked values
Variable-text appearances
EnsureLoadedFieldAppearanceStream walks every widget and inherits /DA, /Q, /V, /DV, /Ff, and /MaxLen values from the field hierarchy or AcroForm
- Left, center, and right quadding use the widget's local appearance coordinates
- Multiline text receives bounded line placement and clipping
- A zero default-appearance font size triggers automatic sizing
- Comb fields place each character independently across
/MaxLencells
Annotation appearance states
GetLoadedAnnotationAppearanceStream resolves normal, rollover, or down appearances and falls back from rollover or down to normal
State dictionaries use /AS, inherited /V or /DV, parent state, /Off, and sole-stream fallback in that order
Selective flattening
FlattenLoadedFormFields paints only selected widget appearances into their owning pages, removes only the matching fields and annotations, and retains every untouched page and field
The default permission gate refuses structural changes under DocMDP and enforces FieldMDP All, Include, and Exclude locks before any page is modified
PDF.BeginIncrementalUpdate('SignedForm.pdf');
PDF.RecalculateLoadedFormFields;
PDF.FlattenLoadedFormFields(['Subtotal', 'Total']);
PDF.SaveIncrementalUpdate('SignedForm-updated.pdf');