WordTemplate can insert certain types of documents into docx files by adding the "document(format)" modifier to the merge field, where format is RTF, HTML, or DOCX (see below).
To add the modifier:
Binding the data:
There are two types of data that can represent a document that can be imported with the document modifier:
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:
If there is content on both sides, paragraph breaks will be inserted on either side of the document:
Having only text before or only text after, will result in a blank paragraph on the other side, such as:
Rtf and html documents maintain their own formatting, so if there is some bold text, or a right-aligned paragraph in the document it will maintain that formatting. This includes the default font for the document, which may not match the default font of the template.
Like regular merge fields document fields can be in an if field's optional text to display, but, because WordTemplate does not parse the contents of the document, document fields in the comparison portion of if fields are not supported, when UpdateIfFields is set to true.
Because inserting an embedded document is not the same as inserting a character run, some formatting and document structures do not support document fields: