Question

I am using ColdFusion 10 Enterprise edition, and am unable to display images when using CFDOCUMENT to generate a PDF. Below is the piece of code I am using:

<cfsavecontent variable="report">
   <table align='center'>
    <cfoutput query="VARIABLES.result">
            <tr>
              <td>
                 <div class='addInfoDetails'>#SHOWINFO#</div>
              </td>
            </tr>
       </cfoutput>  
   </table>
</cfsavecontent>

In the above code, the VARIABLES.result query is coming from database and SHOWINFO is a variable having the content of image and text. For example:

 SHOWINFO  = 
 "<p> Hi This is the test information
     <img alt="image" src="../TestBank/test/info/5KQ.jpg"/>
 </p>"

Here if dump the SHOWINFO variable inside the CFSAVECONTENT, the image displays correctly. But when I convert this into PDF, using CFDOCUMENT, the image is not displaying.

Below is the code block I am using to generate the pdf:

<cfdocument format="PDF" saveasname="TestPDF">
  <cfoutput>#report#</cfoutput>
</cfdocument>

Thanks in advance.

Was it helpful?

Solution

I fixed it by adding the attribute "localUrl = yes" in CFDOCUMENT tag.

Now it is working fine for me.

OTHER TIPS

I'm saving the created pdf and find localUrl="yes" (or =true) fails. Turns out CF generating pdfs for https urls is painfully finicky.

<img src="file:\\\#replace(getCurrentTemplatePath(),"my.cfm")#images\my.png">

Worked for me, in case anyone is scraping the bottom of the barrel for ideas. getCurrentTemplatePath() gets the filename as well as the path, so I had to remove it (hence the replace(...,"my.cfm"). I also tried expandPath(".") and that failed as well.

Didn't try Dave Anderson's intriguing suggestion to grab the image Coldfusion CFDOCUMENT creates a red X

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top