WordTemplate can insert certain types of documents into docx files by adding the "document(format)" modifier to the merge field, where format is one of the following:RTF, HTML, or DOCX (see below).
- rtf - The binary data in the data source will be inserted as an rtf document, e.g.
- html - The binary data in the data source will be inserted as an html document, e.g.
- docx (Introduced in 8.5) - The binary data in the data source will be inserted as an docx document, e.g.
To add the modifier:
- Create or open a WordWriter template (for instructions, see Creating a WordWriter Template).
- Add the "document(rtf)", "document(html)" or "document(docx)" modifier in parentheses to the merge field in which you want to insert the document. For example, change «Product.Doc» to «Product.Doc(document(rtf))»
Binding the data: The data that corresponds to the merge field with the document modifier must be a byte array.
There are two types of data that can represent a document that can be imported with the document modifier:
- byte array
- Introduced in 9.1: A string representing a URI (file path or URL) to the document
If you are providing a file path or URL to the document modifier, you must set WordTemplate.AllowURIs to
This is because URIs can point to potentially malicious files and WordWriter does not have the ability to prevent those files from being embedded in new documents. By default, WordWriter will only allow byte arrays of files to be imported with the document modifier. If
When inserting an embedded document, the document must go at the same level as the paragraphs, to align the template file with the output, document fields should be put in their own paragraph: