奇怪的是这个。
我正在处理一个生成PDF文件的过程,它结合了来自不同来源的数据。我需要完成的最后一个过程是在图像文件中进行合并。
这实际上相当简单,但我遇到的问题是图像文件没有以文件扩展名存储。在本地,我可以更改文件名,但是在生产中这不是一个选项。
因为文件名看起来像:B 71637CB-A49C-0653-EF813918736BDEB7
这样做是行不通的:
<cfimage action="writeTobrowser" source="#FilePath#> 同
<img src="#FilePath#">.关于我如何解决这个问题有什么想法吗?下面是上下文中的代码:
<cfdocument format="PDF" name="report" filename="#fileToDownloadimage#" overwrite="yes">
<cfdocumentsection>
<cfimage action="writeTobrowser" source="#FilePath#.jpg">
</cfdocumentsection>
</cfdocument>发布于 2015-12-16 18:40:41
如果需要将图像嵌入到PDF文档中,请尝试HTML的内联图像功能:
<cfset fileLocation = "/path/to/images/B71637CB-A49C-0653-EF813918736BDEB7">
<cfset imageContent = fileReadBinary(fileLocation)>
<cfset imageContentAsBase64 = toBase64(imageContent)>
<cfoutput>
<img src="data:image/jpeg;base64, #imageContentAsBase64#" />
</cfoutput>发布于 2015-12-16 21:14:41
所以这就是最后起作用的原因:
<cfdocument format="PDF" name="report" filename="#fileToDownloadimage#" overwrite="yes">
<cfdocumentsection>
<cfset fileObject = fileReadBinary('#FilePath#') />
<cfset imageObject = imageNew(fileObject) />
<cfimage action="writeTobrowser" source="#imageObject#">
</cfdocumentsection>
</cfdocument>亚历克斯的回答让我走上了正确的道路,所以我很高兴把荣誉留在原地,因为我并没有接近这一步!
发布于 2015-12-16 18:21:51
您可以尝试创建一个cfm页面,该页面使用cfcontent输出内容,如下所示:
<cfcontent type="image/jpg" file="path/#fielpath#">然后,您会将cfm页面作为您的图像的来源,如
<img src="myFancyImageOuputer.cfm?image=#filepath#">这应该是可行的,但可能需要一些尝试和错误。:)
Ray在这里有一些额外的提示:
http://www.raymondcamden.com/2007/09/14/Serving-up-CFIMages-via-Image-Tags-and-a-NonCF-Friday-contest
https://stackoverflow.com/questions/34316662
复制相似问题