0

Recently my application has been migrated from ColdFusion 8 to 9. I am facing an issue while displaying images in MS Word. Here is my code.

<cfheader name="Content-Disposition" value="attachment;filename=Imagetest.doc">
<cfcontent type="application/msword"> 

Testing Image issue<br>
<cfset logopath = "/ImageIssue/Test_logo.jpg">
<cfoutput>
    <p><img width="141" height="32" src="#logopath#" /><br><br></p>
</cfoutput>

It is giving me an image not found kind of issue with cross mark. This same code was working fine in ColdFusion 8. Does anyone have any suggestions?

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
  • have you checked the image name and whether it is available on the path you are giving ?? – Keshav jha Jun 09 '15 at 12:48
  • post a screenshot of the error you're getting. – Anurag Jun 09 '15 at 17:29
  • The image is there in the mentioned path...The same is working in CF8 windows environment but not in CF9 Unix environment. If I comment the CFHEADER AND CF CONTENT part, The image is getting displayed in the browser. But the same is not happening when exported to word – karunakarreddy kona Jun 10 '15 at 05:36
  • 1
    So you are changing from a Windows environment to a Unix environment. Case matters in Unix and you have mixed case in the URL to your image and file name. Make sure that the case you are requesting matches the actual case of the file and folders on the Unix file system. – Miguel-F Jun 10 '15 at 14:34

1 Answers1

0

First of all you are going in a wrong direction What you are doing is a hack which may be useful in case of basic html.

As @leigh stated here
Basically you are generating html, but using cfheader/cfcontent to tell the browser the content is really a Word document. But it is obviously not a true MS Word file. For the MS Word requirement, most versions of Office can interpret basic html/xml but not complex ones (like - those containing images).

To create a proper word doc with images, you can use Apache POI Project. This means in your coldfusion code you need to use some basic java code to call the poi methods. This java example may help you accomplish what you need.

Insert picture in word document

Community
  • 1
  • 1
Pankaj
  • 1,731
  • 1
  • 13
  • 15