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

FormCalc vs Javascript [PDF / XFA in HTML5]

1 min read

XFA_icon
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.

Keywords

 [“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”];

Operators

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

Separators

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

Some example of replacement

Operational

FormCalcJavascript
 and&&
 or||
 not!
 eq==
 ne!=
 ge>=
 gt>
 le<=
 lt<

Logical

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

eg:

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

 

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

eg:

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

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;
endfor

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

eg;

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

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

eg:

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

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.

 

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

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

Enabling SVG Gzip Compression on Apache and NGINX

Gzip compression is a widely supported method of reducing the size of the content sent from a web server in order to improve the...
Leon Atherton
47 sec read

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2019. All rights reserved.