Hello,
Although using replaceVariableByExternalFile is a good approach in some cases, please note that this method uses altChunk tags that are not supported by some DOCX readers. MS Word supports it, but other such as Google Docs or old LibreOffice versions don't. And this method doesn't allow to customize the imported contents.
We recommend you use importContents, mergeDocx (using in-memory DOCX documents if you don't want to generate extra external files) or overwrite the headers/footers using importHeadersAndFooters.
Regards.