Document Generation Advanced Features in Android

Overview

This is a collection of advanced features for office templates. See here for an overview of basic features and the data model.

Custom tag delimiters

The default tag delimiters are {{ and }}. If you wish to use a different set of delimiters, you can use the functions
OfficeToPDFOptions#SetTemplateLeftDelimiter
OfficeToPDFOptions#SetTemplateRightDelimiter

Strict mode

If a tag's key cannot be located in the data JSON, it will silently be removed from the document. If strict mode is enabled it will instead result in an error. To enable strict mode, use the function
OfficeToPDFOptions#SetTemplateStrictMode By default, strict mode is disabled.

Behavior for empty loops and false conditionals

In both the cases where a loop is given a json value of [] and a conditional is given a json value of false, the body is entirely removed. If the loop/conditional construct was the only thing in it's parent element, it will also remove the parent element.

For example, if an empty loop is the only text in a paragraph, the paragraph will be removed and the proceeding content will be moved up. Another example is an empty row loop, the row itself will be removed.

If this behavior is not desired, a possible workaround is to add a single space character outside of the loop/conditional.

Explicit loop scope

By default, keys are "unspecified scope". Their value is taken dynamically from the most-specific (tightest) loop that contains that key.

For example, a loop
{{loop arr}} {{key}} {{endloop}}
with the JSON data

JSON

1{
2 "key": "*global",
3 "arr": [
4 {"key": "*local"},
5 {}
6 ]
7}

Will result in *local *global.

In order to restrict a template tag to use values from a specific loop, you can specify a scope: {{arr::key}}. The top-level global scope is {{::key}} and in a nested loop you can have a nested scope: {{outer::inner::key}}.`

Table row insertion with insert_rows (.docx, .json)

This is an alternative to table row loops, which should be preferred in most cases.

Table row insertion values are JSON objects, and can only serve as the value for a template key that is in the first row of a table. They have the following required properties:

  • insert_rows: [array of arrays] An array of rows, representing the content to be added. If a table had 3 columns and you wanted to insert two rows within it, insert_rows would expect an array containing two arrays of three items each. The items within the three-member row arrays would be any allowed template value, such as text or an image.
Apryse Docs Image

JSON

1{
2 "tblh1":"Services",
3 "tblh3":"Charge",
4 "billed_items": {"insert_rows": [["Wireless", "", "$42.34"], "..."]},
5 "totals": {"insert_rows": [["", "Tax:", "$8.37"],["", "Balance:","..."]]}
6}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales