Some test text!

Loading...
Guides

Document Generation Advanced Features in C# .NET

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

{
    "key": "*global",
    "arr": [
        {"key": "*local"},
        {}
    ]
}

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.
{
	"tblh1":"Services",
	"tblh3":"Charge",
	"billed_items": {"insert_rows": [["Wireless", "", "$42.34"], "..."]},
	"totals": {"insert_rows": [["", "Tax:", "$8.37"],["", "Balance:","..."]]}
}

Get the answers you need: Support

Upcoming Webinar: How Developers Add Office Viewing Without Downloading | June 9th at 11 am PT

PDFTron SDK

The Platform

NEW

© 2022 PDFTron Systems Inc. All rights reserved.

Privacy

Terms of Use