suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

Do you need to process or display PDF files?

Find out why you should be using IDRSolutions software

FormCalc vs Javascript [PDF / XFA in HTML5]

1 min read

XFA files are complex

This is one of the articles in the XFA series index which investigates the important factors to be considered during the conversion from FormCalc script to Javascript (since none of the current browsers supports formcalc script, therefore the conversion to Javascript is a prerequisite in HTML5) please click here to learn some more interesting stuff about XFA manipulation.

Prior to diving into the conversion we should separate out the keywords, operators and separators used in the FormCalc script.

This separation would be helpful to allow for the replacing the tags with related Javascript supported tags.


 [“and”, “else”, “elseif”, “endif”, “eq”, “ge”, “gt”, “if”, “infinity”,”le”, “lt”, “nan”, “ne”, “not”, “null”, “or”, “then”, “this”, “break”, “continue”,”do”, “downto”, “end”, “endfor”, “endfunc”, “endwhile”, “exit”, “for”, “foreach”,”func”, “in”, “return”, “step”, “throw”, “upto”, “var”, “while”];


[“+”, “{“, “}”, “-“, “%”, “*”, “/”, “;”, “{“, “}”];


[“(“, “)”, “[“, “]”, “,”, “.”, “..”, “.#”, “.*”];

Some example of replacement




If Expression ::= ‘if’ ‘(‘ SimpleExpression ‘)’ ‘then’
ExpressionList ( ‘elseif’ ‘(‘ SimpleExpression ‘)’ ‘then’
ExpressionList )* ( ‘else’ ExpressionList )? ‘endif’


if ( totalMarks < minimum ) then
// fail the student


for Expression ::=’for’ Assignment ‘upto’ Accessor (‘step’ SimpleExpression)?
‘do’ ExpressionList ‘endfor’ |
‘for’ Assignment ‘downto’ Accessor (‘step’ SimpleExpression)?
‘do’ ExpressionList ‘endfor’


var y = 1;
for var x = 1 upto power do
y = y * base

upto keyword denotes increment and downto denotes decrements in for loop. upto keyword performs increment one by one unless it is specified in step keyword

for x=2 upto 100 step 2 do
count = count + 1;

ForeachExpression ::=
‘foreach’ Identifier ‘in’ ‘(‘ ArgumentList ‘)’
‘do’ ExpressionList ‘endfor’


var total = 0.0
foreach expense in ( travel_exp[*], living_exp[*],parking_exp[*] ) do
total = total + expense

WhileExpression ::=
‘while’ ‘(‘ SimpleExpression ‘)’ ‘do’ ExpressionList ‘endwhile’


var count = 0;
while ( count gt 10 ) do
count = count +1;

If you read the code examples above carefully you might have noticed that ecmascript357 type node access mechanism is used in several places of formcalc scirpt.

example amount[1] …. amount[*]

If you have encountered such kind of scenarios then you need to convert the formcalc script to resolveNode method like scripting in Javascript; please read this article to learn more details about resolveNode method in Javascript.

For further information on XFA, please read XFA 3.3 specification for more details.


Our software libraries allow you to

Convert PDF files to HTML
Use PDF Forms in a web browser
Convert PDF Documents to an image
Work with PDF Documents in Java
Read and write HEIC and other Image formats in Java
suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

How to insert an image into a PDF

Recently, we released JPedal 2023.07 which contains the ability to insert images into PDF files. All you need is a copy of JPedal, a...
Jacob Collins
18 sec read