Trouble rendering coldfusion / html page as a docx extension rather than a doc extension

275 Views Asked by At

I am writing an application using ColdBox / ORM. For my problem, I am attempting to have HTML code rendered / downloaded with an .docx file extension rather than a .doc file extension. When downloading the rendered document and trying to open it, I receive a popup saying

Word found unreadable content in ***********. Do you want to recover the contents of this document?

.cfm page

In the file I am trying to have rendered, there is the following in the html tag

 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:w="urn:schemas-microsoft-com:office:word"
 xmlns="http://www.w3.org/TR/REC-html40"

.cfc page

original code

event.renderData(data=fileReadBinary('fileName.doc')
      , contentType='application/msword'
      , isBinary=true);

new code

event.renderData(data=fileReadBinary('fileName.docx')
       , contentType='application/vnd.openxmlformats-officedocument.wordprocessingml.document'
       , isBinary=true);

My expected output is to have the contents of the .cfm file rendered in a .docx file and to be able to open and view it. What actually happens is I get some popup saying "Word found unreadable content in ***********. Do you want to recover the contents of this document?" With buttons for yes / no. Even when choosing yes, I do not see the contents of the file. However, the current code successfully renders as a .doc file which I can view / open.

1

There are 1 best solutions below

1
MattInVail On

As @Ageax mentioned, docx, is a much more complicated file. They are actually zip files. If you take a .docx and rename it to .zip, you can open it and inspect what actually goes into a .docx. You should find the content in the /word/document.xml file of the zip. Instead of trying to create one from scratch, you may want to set up a template of the document that you are trying to create with placeholders. You can unzip the template, edit the document.xml file with your data, zip and rename to docx.