Bouke / docx-mailmerge

Mail merge for Office Open XML (docx) files without the need for Microsoft Office Word.
MIT License
273 stars 104 forks source link

"Word found unreadable content" warning when template file has text boxes #69

Open joaoe opened 5 years ago

joaoe commented 5 years ago

Hi.

Context

My template document has a text box. The original document was an invitation in which the text box was used to mark the margin to cut them into the right size and to also specify a background image.

Current behavior

Generating the merge files seems to go ok and the final document has all the expected text. However, MS Word 2016 complains when first opening it:

Word found unreadable content in <...>.docx. Do you want to recover the contents of this document? If you trust the source o this document, click Yes.

The document is generated using MailMerge.merge_pages(...), e.g.:

merger = MailMerge("testcase.docx")
merger.merge_pages(foo="bar")
merger.write("testcase_generated.docx")

Expected Behavior

Hopefully that warning is not serious. Nonetheless, it should be investigated to see if the generated file is not broken or if we are getting lucky and Word manages to rebuild it.

Steps to Reproduce (for bugs)

  1. Download testcase.zip (link) and unzip in a file locally. The zip file contains testcase.docx and testcase.py.
  2. Run python testcase.py. Obviously this python instance should have docx-mailmerge installed.
  3. Open testcase_generated.docx with Word 2016
  4. The warning message should pop up immediately and block the whole MS Word window.

Environment

Thank you !

joaoe commented 5 years ago

I saved myself from this trouble by using instead a single cell table, with fixed dimensions and an inline image with layout set to behind text.

joaoe commented 5 years ago

I see this here

When using this feature, make sure you don't use comments, footnotes, bookmarks, etc. This is because these elements have an id attribute, which must be unique. This library does not handle this, resulting in invalid documents.

Could it be the same issue ?

tom1200 commented 5 years ago

Hi, This is indeed related to text boxes, witch may have anchors, position, etc ; they are not managed by the merge_pages def. Note that the documentation you quoted refers to a version not released yet by @Bouke. However, this version (def merge_pages replaced by def merge_templates) will not managed either text boxes for the same reasons.