Copy link to clipboard
Copied
I'm using ColdFusion 8.0 running on a Linux server and a MySql db. I want to generate a pdf file that contains a table of info from the db and also a bar chart. The table is fine, but the bar chart isn't displaying. Here's my chunk of code for the chart:
<cfchart format="flash"
yaxistitle="% yield"
chartwidth="640"
chartheight="480">
<cfchartseries type="horizontalbar"
query="bar_info"
valuecolumn="col1"
itemcolumn="col2">
</cfchart>
</cfdocument>
<cfpdf action="write"
source="hreport"
destination="createreportPDF.pdf" overwrite="yes"/>
<cfpdf name="pdf" action="read" source="createreportPDF.pdf"/>
Any suggestions much appreciated. Thank you.
Copy link to clipboard
Copied
I'd try format="jpg" instead of flash.
Copy link to clipboard
Copied
I've tried all the options I could find for chart format, which was flash, jpg, png and swf and none of them diaplayed in the pdf file ![]()
Copy link to clipboard
Copied
Can you post a complete & self-contained reproduction case that demonstrates this not working?
--
Adam
Copy link to clipboard
Copied
Here's my code. It produces a web page that has a link to generate a pdf file that should display the same info. I've included the web page image and pdf file image. I'm using adobe acrobat reader v10. Please let me know if you need anything else. Thank you.
<cfinvoke component="hybrid"
method="get_expmeans"
returnvariable="expmeans">
<cfif IsDefined('FORM.hybrid_id')>
<cfinvokeargument name="hybrid_id"
value="#Trim(FORM.hybrid_id)#">
<cfelseif IsDefined('URL.hybrid_id')>
<cfinvokeargument name="hybrid_id"
value="#Trim(URL.hybrid_id)#">
<cfelse>
<cfinvokeargument name="hybrid_id"
value="">
</cfif>
</cfinvoke>
<cfinvoke component="hybrid"
method="clear_tmp">
</cfinvoke>
<cfloop query="expmeans">
<cfinvoke component="hybrid"
method="put_barchart">
<cfinvokeargument name="yieldpc"
value="#NumberFormat((expmeans.yield_art_kg_ha - expmeans.yield_art_Artemis)/expmeans.yield_art_Artemis * 100, 9.99)#">
<cfinvokeargument name="fieldtrial_name"
value="#expmeans.fieldtrial_name#">
</cfinvoke>
</cfloop>
<cfinvoke component="hybrid"
method="get_bar_info"
returnvariable="bar_info">
</cfinvoke>
<!--- Title and page template --->
<cfinclude template="/artemis/Templates/artemishead1.cfm">
<title>Hybrid Report</title>
<cfinclude template="/artemis/Templates/artemishead2.cfm">
<!--- page contents start here --->
<h2><font color="#003399">Hybrid Report</font></h2>
<cfoutput>
<table>
<TR ALIGN="CENTER" bgcolor="##e0e0e0">
<td valign="top" nowrap><strong>Fieldtrial</strong></td>
<td valign="top" nowrap><strong>Leaf biomass<br /> t/ha</strong></td>
<td valign="top" nowrap><strong>Art %</strong></td>
<td valign="top" nowrap><strong>Art yield<br /> kg/ha</strong></td>
<td valign="top" nowrap><strong>Compare artemis</strong></td>
<td valign="top" nowrap><strong>Compare LC</strong></td>
<td valign="top" nowrap><strong>Indian flowering</strong></td>
</tr>
</cfoutput>
<cfoutput query="expmeans">
<!--- what colour should this row be?--->
<cfif CurrentRow MOD 2 IS 1>
<cfset bgcolor='##f9f9fb'>
<cfelse>
<cfset bgcolor='##e0e0e0'>
</cfif>
<tr bgcolor='#bgcolor#'>
<td align = "Center">#expmeans.fieldtrial_name#</td>
<td align = "Center">#expmeans.yield_ldw_kg_ha/1000#</td>
<td align = "Center">#expmeans.conc#</td>
<td align = "Center">#expmeans.yield_art_kg_ha#</td>
<td align = "Center">#NumberFormat((expmeans.yield_art_kg_ha - expmeans.yield_art_Artemis)/expmeans.yield_art_Artemis * 100, 9.99)#</td>
<td align = "Center">#NumberFormat((expmeans.yield_art_kg_ha - expmeans.yield_art_localcheck)/expmeans.yield_art_localcheck * 100, 9.99)#</td>
<td align = "Center">#NumberFormat(ftsummary.number_floweringplants_final / ftsummary.plant_count_wholeplot_final * 100, 9.9)#</td>
</tr>
</cfoutput>
</table>
<br />
<!--- draw the bar chart --->
<cfchart format="flash"
yaxistitle="% over artemis"
chartwidth="640"
chartheight="480">
<cfchartseries type="horizontalbar"
query="bar_info"
valuecolumn="col1"
itemcolumn="col2">
</cfchart>
<br />
<!--- create the PDF file --->
<cfdocument name="hreport" format="pdf">
<h2><font color="#003399">Hybrid Report</font></h2>
<h2>Report for hybrid <cfoutput>#variables.hybrid_id#</cfoutput></h2>
<cfoutput>
<table>
<TR ALIGN="CENTER" bgcolor="##e0e0e0">
<td valign="top" nowrap><strong>Fieldtrial</strong></td>
<td valign="top" nowrap><strong>Leaf biomass<br /> t/ha</strong></td>
<td valign="top" nowrap><strong>Art %</strong></td>
<td valign="top" nowrap><strong>Art yield<br /> kg/ha</strong></td>
<td valign="top" nowrap><strong>Compare artemis</strong></td>
<td valign="top" nowrap><strong>Compare LC</strong></td>
<td valign="top" nowrap><strong>Indian flowering</strong></td>
</tr>
</cfoutput>
<cfoutput query="expmeans">
<!--- what colour should this row be?--->
<cfif CurrentRow MOD 2 IS 1>
<cfset bgcolor='##f9f9fb'>
<cfelse>
<cfset bgcolor='##e0e0e0'>
</cfif>
<tr bgcolor='#bgcolor#'>
<td align = "Center">#expmeans.fieldtrial_name#</td>
<td align = "Center">#expmeans.yield_ldw_kg_ha/1000#</td>
<td align = "Center">#expmeans.conc#</td>
<td align = "Center">#expmeans.yield_art_kg_ha#</td>
<td align = "Center">#NumberFormat((expmeans.yield_art_kg_ha - expmeans.yield_art_Artemis)/expmeans.yield_art_Artemis * 100, 9.99)#</td>
<td align = "Center">#NumberFormat((expmeans.yield_art_kg_ha - expmeans.yield_art_localcheck)/expmeans.yield_art_localcheck * 100, 9.99)#</td>
<td align = "Center">#NumberFormat(ftsummary.number_floweringplants_final / ftsummary.plant_count_wholeplot_final * 100, 9.9)#</td>
</tr>
</cfoutput>
</table>
<br />
<!--- draw the bar chart --->
<cfchart format="jpg"
yaxistitle="% over artemis"
chartwidth="640"
chartheight="480">
<cfchartseries type="horizontalbar"
query="bar_info"
valuecolumn="col1"
itemcolumn="col2">
</cfchart>
</cfdocument>
<cfpdf action="write"
source="hreport"
destination="createreportPDF.pdf" overwrite="yes"/>
<cfpdf name="pdf" action="read" source="createreportPDF.pdf"/>
<b><a href="/artemis/data/Plant/hybrids/createreportPDF.pdf">Create PDF file</a></b>


Copy link to clipboard
Copied
OK, I didn't suggest just pasting in all your code (most of which is irrelevant to the problem you're trying to work through), I asked for a self-contained reprodcution case. This should be the minimum amount of code that demonstrates the problem. And it should be entirely self-contained; so no calls to CFCs, not reliance on querying DB data, just probably half a dozen lines of code that replicates what you're seeing, but does nothing else.
--
Adam
Copy link to clipboard
Copied
Ok, I didn't know what a self-contained reproduction case was, but if it's what you describe then I thought that's what I did in my original post.
Copy link to clipboard
Copied
if it's what you describe then I thought that's what I did in my original post.
Not quite, it relies on having a query result present. Anyway I bodged it into this:
<cfdocument format="PDF" name="hreport">
<cfchart format="png"
yaxistitle="% yield"
chartwidth="640"
chartheight="480">
<cfchartseries type="horizontalbar">
<cfchartdata item="arse" value="4" >
</cfchartseries>
</cfchart>
</cfdocument>
<cfpdf action="write"
source="hreport"
destination="createreportPDF.pdf" overwrite="yes"/>
Note I changed the format to PNG as Dan suggested in his first post, and it now works absolutely fine and displays in the PDF.
Copy link to clipboard
Copied
Unfortunately it still doesn't work on my system... can you think of any reason why?
Copy link to clipboard
Copied
Nope.
If all else fails, use CFCHART *outside* the CFDOCUMENT tag and have it write the chart to disk. Then just read it into your document as you would any other image.
If not even that works, then you have issues other than CFCHART.
Copy link to clipboard
Copied
If all else fails, use CFCHART *outside* the CFDOCUMENT tag and have it write the chart to disk. Then just read it into your document as you would any other image.
I've not tried this, but could one not bypass the filesystem and save the chart to a variable, then output it with CFIMAGE? Obvious CF saves the binary data to file unde the hood, but it saves having to write code to do it.
--
Adam
Copy link to clipboard
Copied
could one not bypass the filesystem and save the chart to a variable, then output it with CFIMAGE?
Absolutely yes, that was going to be my next suggestion if it didn't work. I was thinking if simple IMG tag didn't work it'd save time messing about with more complex stuff ![]()
But yes - as Adam suggests there is no need to save it to disk in a production environment.
Copy link to clipboard
Copied
Hi guys, I've finally managed to solve my problem. I tried all your suggestions to no avail, and after hours of scouring the CF docs pages I found my solution, which is mind-bendingly simple. Just include "localURL="yes" in the cfdocument tag eg. <cfdocument format="PDF" name="hreport" localUrl="yes"> Doh.
Copy link to clipboard
Copied
if it's what you describe then I thought that's what I did in my original post.
Not quite, it relies on having a query result present. Anyway I bodged it into this:
I just presumed that was a code fragment as it doesn't have an opening CFDOCUMENT tag.
Owain's example is a perfect demonstration of a repro case. When troubleshooting problems like this, one should ALWAYS pare the situation down to something like this before posting here. It removes all the other potential contributing factors, and isolates the issue. Much easier to troubleshoot. By way of example Owain was able to resolve the problem pretty quickly once he concocted a working repro case. I could have done this too granted, but I think the burden should be on the person with the issue to demonstrate what they've tried so there's no false assumptions being made.
--
Adam
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more