cfchart not printing in PDF

落花浮王杯 提交于 2020-01-11 14:09:49

问题


I'm trying to print PDF from HTML using cfdocument. The code works fine when I access it through localhost, but when I use static IP to test it online on the same server it timeouts.

I tried cfhtmltopdf it didn't timeouts but it doesn't generate the chart and shows "image missing icon". nor charts get generated nor images. text gets printed fine. And it takes like 20 to 30 seconds to generated the PDF when an image or chart is used.

I tried this on CF11 32bit and 6bit both having same issue. Even the simplest codes fails:

<cfhtmltopdf>
<!DOCTYPE html>
<html>
<body>
    <div class="pdf_logo" style="margin-bottom: 20px;">
        <a href="##"><img src="images/logo.png" width="180"></a>
    </div>
</body>
</html>
</cfhtmltopdf>

回答1:


I've encountered a similar issue with cfhtmltopdf. In my case, I was using a cfimage tag, and the images were being rendered in the PDF document very sporadically.

I suspect that the rendering of the cfhtmltopdf tag happens asynchronously, in a separate thread from any rendering that may happen inside that tag (for example, cfimage or cfchart). So the cfhtmltopdf tag will finish rendering, and it won't have the results from the rendering of cfimage or cfchart, so it displays the "broken image" icon because it can't find the source.

So this solution based on ColdFusion documentation† might help you:

<!--- 1. Generate the chart as a jpeg image. --->
<cfchart name="myChart" format="jpg">             
    <cfchartseries type="pie"> 
        <cfchartdata item="New Vehicle Sales" value=500000> 
        <cfchartdata item="Used Vehicle Sales" value=250000> 
        <cfchartdata item="Leasing" value=300000> 
        <cfchartdata item="Service" value=400000> 
    </cfchartseries> 
</cfchart> 

<!--- 2. Write the jpeg image to a temporary directory. --->
<cffile  
    action="write"  
    file="#ExpandPath('/charts/vehicle.jpg')#"
    output="#myChart#" />

<!--- 3. Generate the PDF file. --->
<cfhtmltopdf>
<!DOCTYPE html>
<cfoutput>
<html>
    <body>
        <div class="chart">
            <!--- This image tag refers to the file created by cffile --->
            <img src="/charts/vehicle.jpg" />
        </div>
    </body>
</html>
</cfoutput>
</cfhtmltopdf>

† Based on the example here: http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7934.html




回答2:


Your problem is probably with resolution of the path to the image. try an absolute path (http://) Or a file path (file:\) ... try resolving the image from the desktop of the server itself.

Remember that the server internally must resolve your images/logo.png into something like . If (for example) your pdf generating cfm is in a folder that is not the root, the server may resolve it to http://blah.com/some folder/images/logo.png - which naturally won't work because there's no "images" folder in there.

Other possibilities? Your server can't resolve an "internal" natted address, or is trying to use an external non-natted address through the firewall interface.

Fortunately almost all these problems can be easily tested or resolved. You will also save yourself headaches by simply using the file method to include any resources into your PDF file.

For more on resolution issues see my post on Network address resolution and Cfdocument.

Hope this helps! good luck.



来源:https://stackoverflow.com/questions/37600156/cfchart-not-printing-in-pdf

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