PDF Generator API
Go to website
Back
Articles on:
Expression language
The expression language allows writing a mathematical and logical expression to manipulate the value displayed by component.
What is Expression Language?
Expression language in PDF Generator API is a specific programming language that allows writing mathematical and logical expression to manipulate the value displayed by component. Expression language can be written into the "Text" component "Raw value" under the "Formatting" view. Example expression {% 2 + {dataFieldName} + {dataFieldName2}*0.5 %}
Very popular
Common use-cases of the Expression language
Using filter and iterate function Let's say you have an array of line items, where items can be of different type (e.g. "Food", "Drinks", etc...) and you need to get a SUM of a specific type. Then you can do it using a combination of filter and iterate function: {% sum(iterate(filter({line_items}, 'type == "Drinks"'),'total_price')) %} Example JSON dataset:
Few readers
Supported operators
Arithmetic Operators + (Addition) {% 2 + 3 %} >> 5 - (Subtraction) {% 7 – 4 %} >> 3 * (Multiplication) {% 2 * 3 %} >> 6 / (Division) {% 9 / 3 %} >> 3 % (Modulus) {% 10 % 3 %} >> 1 ** (Pow) {% 5 ** 2 %} >> 25 Logical Operators ! (not) {% !true ? "true": "false" %} >> false && (And) {% true && false ? "true": "false" %} >> false || (Or)
Very popular
Functions
Number functions The Text component must have the Format set to Number. Format number Format a number with grouped thousands and optionally decimal digits. {% number_format([float number], [decimal_places], [decimal_separator], [thousands_separator]) %} Round Round the float number based on the precision from the second parameter. {% round([float number], [integer precision]) %} Ceil Rounds to the nearest integer up. E.g. 2.1 => 3.
Very popular