Thursday, 11 November 2021

use UTF-8 in docxtpl (DocxTemplate) and Jinja2

I am generating docx documents by using docxtpl and Jinja2. I produced it by using as explained in the manual a python matrix/dictionnary feeded by data from XML files. When XML files store latin-1 data my docx are well generated but when the contents are in utf-8 encoding (like polish language) Jinja2 or docxtpl do not keep this encoding and the docx is apparently not well formatted.

How to pass an encoding option or circle this issue?

My process is very simple:

doc = DocxTemplate(<my_jinja2_docx_template>)
doc.render(<my_dictionnary_with_data>)
doc.save(<my_docx_file>)

Thanks a lot



from use UTF-8 in docxtpl (DocxTemplate) and Jinja2

No comments:

Post a Comment