Embedding Image in Microsoft Word using ColdFusion

822 views Asked by At

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?

1

There are 1 answers

0
Pankaj On

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