earachefl
earachefl

Reputation: 1890

Unable to include image in pdf using cfdocument/cfcontent

I'm streaming images from outside the web root, using cfcontent. While the images are displayed correctly when the various pages are called directly in the browser, the images show a red X inside the generated pdf. On the export page:

<cfsavecontent variable = "gridCode">
    <cfinclude template="pathToGeneratedPage.cfm" >     
</cfsavecontent>
<cfdocument format="pdf" filename="#filename#" overwrite="yes" localUrl="yes">
    <cfdocumentsection >
        <cfoutput>#gridCode#</cfoutput>     
    </cfdocumentsection>
</cfdocument>

On the page with the content to be generated:

<img src="pathToDisplayPhoto.cfm?image=#someImage#" />

On the displayPhoto.cfm page:

<cfcontent type="image/*" file="#pathToUploadFolderOutsideWebRoot##url.image#" deleteFile = "No">

I included the cfdocument attribute localUrl="yes" because the default (no) was not working. Setting explicitly to "no" doesn't work either.

Any suggestions?

Upvotes: 2

Views: 3550

Answers (2)

gordon
gordon

Reputation: 1182

I'm saving the created pdf and find localUrl="yes" (or =true) failed.

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

Worked for anyone 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.

Upvotes: 2

Dpolehonski
Dpolehonski

Reputation: 958

You have 'localUrl' set to yes, this means that Coldfusion will look at the file paths in the images and try and find them on the harddrive without making an HTTP or HTTPS call, so Its trying to open 'pathToDisplayPhoto.cfm?image=#someImage#' as an Image, but because its not an HTTP request it won't proccess the CFML.

If you set loclUrl to No that should fix the issue.

cfdocument ref - look for localUrl in the params list.

Upvotes: 1

Related Questions