From b3094f660a1dee8b2e70b8693527fb7611c92eba Mon Sep 17 00:00:00 2001 From: ericdufresne Date: Tue, 11 Jun 2019 10:03:53 -0400 Subject: [PATCH] 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. --- docxtpl/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docxtpl/__init__.py b/docxtpl/__init__.py index 1cc6eca..0286f5f 100644 --- a/docxtpl/__init__.py +++ b/docxtpl/__init__.py @@ -463,6 +463,8 @@ class DocxTemplate(object): DocxTemplate(docx_file).save(tmp_file) tmp_file.seek(0) docx_file.seek(0) + docx_file.truncate() + docx_file.seek(0) else: tmp_file = '%s_docxtpl_before_replace_medias' % docx_file