One problem that I ran into while creating PDF's in Coldfusion recently was with including images. Despite using what I thought was a valid path (since it would show up in my browser) and using the correct syntax, my images were showing up as red x's. I found out that there is a little trick to including images in a PDF in CF.
After reading through many different blog entries, I learned that there are many reasons as to why an image won't show up in a PDF on a CF server. Basically, it came down to it being some sort of permissions or security issue between the HTTP request sent from the PDF for the image and the Coldfusion server.
Including an image like this didn't work:
However, including an image using the File system, rather than HTTP works:
Note the 3 forward slashes, as opposed to two.
Team Ravenglass
#1 by Lee on 6/10/10 - 9:23 AM
<!--- Function for Image path --->
<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>
<img src=#localURL(ImagePath)# />
#2 by Ben Nadel on 6/10/10 - 10:32 AM
#3 by Bridget on 6/10/10 - 10:50 AM
@Ben I did see the "localUrl" attribute for the cfdocument tag and did try setting it to "yes" but it still wouldn't work. Here are some of the syntaxes that I tried:
<code>
<img src="/stn_logo.gif" />
<img src="#expandpath('/stn_logo.gif')#" alt="Signature Travel Network" />
</code>
I did just re-check the Adobe docs (http://livedocs.adobe.com/coldfusion/8/htmldocs/he...) and it specifies that the img syntax should look like:
<code>
<image src="images/rose.jpg">
</code>
#4 by Ben Nadel on 6/10/10 - 10:53 AM
#5 by Bridget on 6/10/10 - 10:55 AM
#6 by Ben Nadel on 6/10/10 - 10:57 AM
#7 by Rene Ramos on 9/9/10 - 11:56 AM
Just wanted to say thank you!
#8 by Abram on 10/14/10 - 4:39 PM
#9 by Bridget on 11/10/10 - 10:34 AM
#10 by Joseph Lee on 1/26/11 - 12:28 PM