2
votes

I am having a problem displaying images within cfdocument. I have tried several different options without luck (please see test code below).

It seems that cfdocument recognizes there is an image file there, because the size of the table cell changes. Yet still it doesn't display content of the image. I would appreciate any help.

    <cfdocument format="PDF" localURL = "yes">
    <p style="background-color:#006633">

    <table border="1">
    <tr><td><cfoutput>
            output from "file:///#ExpandPath('CEUCertificate_ABondy3.jpg')#" 
            </cfoutput>
        </td>
        <td style="background-color:white">
        <cfoutput>
           <image src="file:///#ExpandPath('CEUCertificate_ABondy3.jpg')#"> 
        </cfoutput>
        </td>
    </tr>
    <tr><td><cfoutput> output from #ExpandPath('CEUCertificate_ABondy3.jpg')#  </cfoutput> </td>
        <td>
        <cfoutput>
            <image src="#ExpandPath('CEUCertificate_ABondy3.jpg')#"> 
        </cfoutput>
        </td>
    </tr>
    <tr><td style="background-color:red">
            Output from: img src="CEUCertificate_ABondy3.jpg"
        </td>
        <td style="background-color:red"> 
            <img src="CEUCertificate_ABondy3.jpg"/>
        </td>
    </tr>
    <tr>
        <td style="background-color:white">
            output from image src="CEUCertificate_ABondy3.jpg"
        </td>
        <td>
            <cfoutput>
            <image src="CEUCertificate_ABondy3.jpg">
            </cfoutput>
    </tr>
    <tr>
        <td>Output from local url</td>
        <td>
             <cfoutput>
             <img src=#localUrl("CEUCertificate_ABondy3.jpg")#>
             </cfoutput>
        </td>
    </tr>
    </table>
    </p>
    </cfdocument>

    <cffunction name="localUrl" >
      <cfargument name="file" />

      <cfset var fpath = ExpandPath(file)>
      <cfset var f="">
      <cfset f = createObject("java", "java.io.File")>
      <cfset f.init(fpath)>

      <cfreturn f.toUrl().toString()>
    </cffunction>
2
What happens if you use <img src="/cde/mobileweb/CEUCertificate_ABondy3.jpg"/> ? - Miguel-F
How much ram have you allocated to the CF instance? Have you tried increasing it? - Henry
Henry, I don't have control over it. - Janusz Chudzynski

2 Answers

1
votes

For your initial question, you need to reference the images in your cfdocument tag as you would with any other HTML page; <img src="url-to-the-image" />. So this should work for you.

<img src="/cde/mobileweb/CEUCertificate_ABondy3.jpg"/>

Now that you have made that change the page is timing out. This is probably due to how the image was created. See this page here. Which I found from Charlie's page here.

Try opening that image in an editor and re-saving it. Then see if the processing time decreases.

I found some more discussion about this on Ben Nadel's blog here.

0
votes

Instead of messing with ExpandPath() and file://, code it as a normal html and make sure it works first. Then use localUrl="true" in your <cfdocument>