Google charts to pdf

Is it possible to generate the PDF with PIE/BARchart data if we use google charts ?
Who is Participating?

No, You can store google charts as image and after that use it in your PDF.
Here the code Snippet, I just code it now and works fine for me. =)

// Google Chart to Image - By VanHackman

	$chart = file_get_contents(',49&chs=350x150&chl=Foo|Bar');
	$handle = fopen("ChartImage.png", "w");
	fwrite($handle, $chart);
	echo '<img src="ChartImage.png" alt="crash"/>';


Open in new window


No, you must use another library/class to handle the PDF generation.

I suggest you FPDF

So, you generate your Chart and after that, you manipulate and use FPDF to put it in a PDF.


I hope that my answer helps you!
Desire2changeAuthor Commented:
I am using exactly the same that is FPDF
but the problem is I have google charts in my report
when i say $pdf->Image('google chart url')
it says invalid image format

So, I am using the following code to save the google chart as image .
but the resultant file graph.png is created with 0 bytes i.e. blank

$url=",10,30,10&cht=p3&chl=20|10|30|10&chdl=Total Number Of Machines Scanned|Low|High|Medium&chdlp=b&chco=00FF00|0000FF|FF0000|00FFFF";

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions


Yes, that is a little bit problem that you could have, the solution is use the charts that are image based.
Desire2changeAuthor Commented:
so you mean there is no way to store google charts as image on the system ??
Desire2changeAuthor Commented:
the same thing i did and not working for me, strange!
is there any setting i need to change
when i say:
$chart = file_get_contents(',49&chs=350x150&chl=Foo|Bar');

the $chart is empty


So rare, The code snippet works perfect for me.
Do you have the fopen_wrappers() enable?

"A URL can be used as a filename with this function if the fopen wrappers have been enabled."

Do you have to turn "ON" the "allow_url_fopen" in your php.ini
I was having trouble with this code and found that by urlencoding the labels it worked for me - probably because my labels were being drawn from a database and had spaces in. Just extra information in case any one else has the same problem I had.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.