image not displayed in cfdocument

对着背影说爱祢 提交于 2019-12-11 07:13:08

问题


I found a curios situation couple of days back which I was able to solve after losing a lot of temper.

Well the issue is I am placing an image inside a dynamically created pdf(using cfdocument). I am able to see the image when I run my website locally. But once I upload the code to prod I get the broken-image at the image placeholder.


回答1:


accepting Al everett's suggestion, the solution to problem is briefed. The issue of the image not being displayed was due to the HTTPS access of the document and images was not being downloaded. so I used the below work around:

<cfdocument format="pdf">
 <cfoutput>
 Some html content
 <br>
 <img src=#localUrl("img1.gif")#><br>
 <img src=#localUrl("images/img.jpg")#>
 </cfoutput>
</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:


This is usually caused by internal path versus external path. You are likely referencing a domain in the URL which may not be valid internally. One solution is to update your server's host file to include all valid domains and their internal network IP equivalents. Then when the domain is requested on the server, the internal IP is referenced instead of invalid external IP.

http://www.google.com/search?q=host+file+internal+domain



来源:https://stackoverflow.com/questions/6109183/image-not-displayed-in-cfdocument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!