Truncate zip file before re-writing it. This prevents a misplaced zip file table of contents which can cause Microsoft word to go into recovery mode for a newly generated document.

This commit is contained in:
ericdufresne 2019-06-11 10:03:53 -04:00
parent 671c7c78a7
commit b3094f660a

View File

@ -463,6 +463,8 @@ class DocxTemplate(object):
DocxTemplate(docx_file).save(tmp_file) DocxTemplate(docx_file).save(tmp_file)
tmp_file.seek(0) tmp_file.seek(0)
docx_file.seek(0) docx_file.seek(0)
docx_file.truncate()
docx_file.seek(0)
else: else:
tmp_file = '%s_docxtpl_before_replace_medias' % docx_file tmp_file = '%s_docxtpl_before_replace_medias' % docx_file