Skip to main content
Participant
September 12, 2011
Question

cfcontent not invoking MS Word

  • September 12, 2011
  • 1 reply
  • 2098 views

Hi all

I am using Coldfusion 7.

I have a .rtf file as a template, with various placeholders placed throughout. I use cffile to read this template. I then have a query that replaces the placeholders with data. I then attempt to invoke MS Word to save the file as a .doc file. The problem is I only get garbage code once I execute this. I believe I am looking at the actual text data of the .rtf file, and Word is never invoked.

       <!--- Read template into variable "rtf" --->
     <cffile action="read" file="#fileLocation##fileName#" variable="rtf">


    <!--- Replace placeholders with data --->
     <cfset rtf = replace(rtf, "%InvoiceNumber%", trim(invoice), "ALL")>
     blah blah blah.......
    


    <!--- Suggest default filename for document --->
     <cfheader name="Content-Disposition" value="filename=INVOICE.doc">
    
     <!--- Set the content type so Word is invoked --->
     <cfcontent type="application/msword">
     <cfoutput>#rtf#</cfoutput>

Any suggestions? Thanks in advance.

-J

    This topic has been closed for replies.

    1 reply

    Inspiring
    September 12, 2011

    Part  of your problem may be that the MIME type and file content don't match.  You are telling the brower to expect a Word document, but you are sending an RTF document.  Try using the MIME type application/rtf.  You will need to depend on the user saving the RTF file to Word format.

    You might try something like the sample below which I have *not* tested.  This would replace the cfcontent and cfoutput block in the code you posted.  This *should* output the RTF document to the client.

    <cfheader name="Content-Disposition" value="attachment;filename=myfile.rtf">

    <cfcontent type="application/rtf" variable="#ToBinary(ToBase64(rtf))#" reset="yes">

    Question:

    When you say "I then attempt to invoke MS Word to save the file as a .doc file." do you mean on the client side or server side?

    Participant
    September 12, 2011

    JR thanks for your response. I will have to try this out.

    I am talking about client side.