来自cfdocument中二进制文件的cfimage [英] cfimage from binary in cfdocument
问题描述
我正在动态编写PDF,并且正在为电子票务目的在文档上创建QR码
I am writing a PDF dynamically, and am creating a QR code on the document for eTicketing purposes
我将cfdocument localurl = y设置为包含其他图像,效果很好,但是由于我使用API调用来获取qrCode的二进制文件,因此使用cfimage显示图像,因此它只显示红色的X
i set my cfdocument localurl=yes to include a different image, which works fine, but since I am using an API call to get the binary for the qrCode, the using cfimage to display the image, it is only showing a red X
<cfdocument format="PDF" overwrite="Yes" localUrl="yes" pageType = "letter">
<body>
<cfoutput>
<section id="header">
<img src="file:///#ExpandPath('images/header.png')#"/>
<cfimage action="writeToBrowser" source="#rc.qrCode#" />
</cfoutput>
</body>
</html>
</cfdocument>
源变量rc.qrCode是一个二进制响应,在我将其放入cfdocument之前,它都能正常工作像这样的网址 http://mysite/CFFileServlet/_cf_image/_cfimg-7945382145198648283.PNG
作为图像源
the source variable rc.qrCode is a binary response that works perfectly until i place inside cfdocument, it generates a url like this http://mysite/CFFileServlet/_cf_image/_cfimg-7945382145198648283.PNG
as image source
我确信这与localurl和file:///有关,我只是一个不为所知的原因,足以知道为什么
i am sure this has todo with localurl and file:///, i just an not knowledgable enough to know why
推荐答案
不需要使用物理路径,而是使用页面的相对路径。
例如
如果您在根文件夹的index.cfm和图像文件夹中的图像中进行编码
Do not need to use physical path rather use relative path to your page. e.g. If you code in index.cfm of root folder and image inside images folder
try< img src = images / header.png>,请注意
try <img src="images/header.png"> , Note that it should not start with root path rather relative to your file.
UPDATE
writetoBrowser内部将文件写入硬盘驱动器到其临时位置(主题为C:\ColdFusion10\cfusion\tmpCache\CFFileServlet),并在将其呈现到浏览器时使用 / CFFileServlet / _cf_image / _cfimg1592404668342998556之类的相对路径。 PNG,您可以说ColdFusion在内部将CFFileServlet目录与所有ColdFusion站点进行映射,但请注意前导斜杠,这会导致localurl = true出现问题。由于localurl = true要么需要物理路径,要么需要文档的相对路径。
writetoBrowser internally write file to hard drive to it's temporary location (topically, C:\ColdFusion10\cfusion\tmpCache\CFFileServlet) and while rendering it to browser it use relative path like "/CFFileServlet/_cf_image/_cfimg1592404668342998556.PNG", you can say that ColdFusion internally map CFFileServlet directory with all coldfusion site but notice leading forward slash and this makes issue with localurl=true. Since localurl=true either need physical path or relative path to your document.
好主意是代替writetobrowser,您可以将相同的图像写入您所在位置的硬盘,并提供物理路径在img标签中。我不认为这不会有任何性能问题,因为当您使用writetobrowser属性时,ColdFusion在内部做同样的事情:)
Good idea is instead of writetobrowser you can write same image to harddrive at your location and give physical path in img tag. I do not this there will any performance issue since ColdFusion internally doing same thing when you are using writetobrowser attribute :)
这篇关于来自cfdocument中二进制文件的cfimage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!