Bounded XFA FormCalc and JavaScript
HotPDF đánh giá các calculate script của XFA trong lúc flatten form, với đường FormCalc luôn sẵn sàng và có giới hạn, cùng đường QuickJS rộng hơn vẫn bị tắt cho tới khi ứng dụng chủ động bật
Extended FormCalc
FormCalc expressions support arithmetic, strings, booleans, comparison operators, short-circuit And, Or, and Not, plus the lazy If(condition, whenTrue, whenFalse) branch
Sum, Avg, Min, Max và Count chấp nhận đối số hỗn hợp gồm scalar và SOM node-set, dùng path dạng rooted, direct, indexed, wildcard hoặc descendant như $record.rows[*].amount; chỉ nhánh được chọn của If mới được đánh giá, nên một nhánh không dùng nhưng không hợp lệ sẽ không làm phép tính bị từ chối
Các lời gọi lồng nhau có thể kết hợp kết quả số, chuỗi và node-set, với hỗ trợ tất định cho At , Choose , Concat , LTrim , RTrim , Str , Stuff , Null , Sign , Exp , Log , Sin , Cos , Tan , Deg2Rad , Rad2Deg , Within và Oneof
Hàm do người dùng định nghĩa, vòng lặp, phép gán, mệnh đề picture theo locale và các hàm mạng nằm ngoài tập con native và fail closed
InstanceAdd(name, count) and InstanceRemove(name, index) dispatch through OnXFAInstanceAction only after argument and operation-budget validation
Optional JavaScript
Set THotPDF.XFAJavaScriptEnabled to True before ApplyXFAAsAcroForm or FlattenLoadedXFA to run scripts whose contentType selects JavaScript
Runtime hỗ trợ control flow JavaScript thông thường và typed array gốc như Float64Array, nhưng không nhận object file, process, network, browser hay application nào; fetch, XMLHttpRequest, WebSocket, require, process và Deno đều không khả dụng
var
Budgets: THPDFXFAFormScriptBudgets;
begin
Budgets := THPDFXFAFormScriptBudgets.Default;
Budgets.MaxElapsedMilliseconds := 100;
Budgets.JavaScriptMemoryBytes := 8 * 1024 * 1024;
PDF.XFAFormScriptBudgets := Budgets;
PDF.XFAJavaScriptEnabled := True;
PDF.OnXFAInstanceAction := HandleXFAInstanceAction;
PDF.ApplyXFAAsAcroForm(XDPBytes, False);
end;
Script context
JavaScript receives a mutable this.rawValue, an event.value, and a frozen xfa facade
xfa.get(name, index)reads one collected data valuexfa.values(name)trả về một bản sao đã freeze của mọi giá trị lặp lạixfa.resolveNode(name)andxfa.resolveNodes(name)expose read-only raw-value viewsxfa.addInstance(name, count)andxfa.removeInstance(name, index)queue validated host callbacks
Budgets and telemetry
THPDFXFAFormScriptBudgets bounds script bytes, FormCalc operations, elapsed time, expression depth, repeated-array items, value bytes, instance operations, JavaScript memory, JavaScript stack use, and interrupt checks
Ngân sách stack đóng vai trò giới hạn đệ quy, còn ngân sách thời gian và interrupt dừng các vòng lặp không kết thúc; script vượt bất kỳ giới hạn nào sẽ fail closed và thêm một chẩn đoán vào XFAFlattenWarnings
XFAFlattenScriptsEvaluated, XFAFlattenScriptsRejected, and XFAFlattenInstanceOperations report the latest flattening pass
Direct runtime integration
Overload mở rộng của HPDFXFAFlatten nhận trực tiếp TXFAFormScriptOptions và TXFAFormInstanceAction; gán TXFAFormScriptOptions.JavaScriptEvaluator để chuyển sang QuickJS binding tĩnh hoặc một evaluator khác do ứng dụng sở hữu, mà vẫn giữ nguyên wrapper và các ngân sách
See TXFAFormScriptOptions, TXFAFormScriptLimits, THPDFXFAFormScriptBudgets, and THPDFXFAInstanceAction