Google charts to pdf

Posted on 2010-01-04
Last Modified: 2013-12-20
Is it possible to generate the PDF with PIE/BARchart data if we use google charts ?
Question by:Desire2change
    LVL 11

    Expert Comment


    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!

    Author Comment

    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";

    LVL 11

    Expert Comment


    Yes, that is a little bit problem that you could have, the solution is use the charts that are image based.

    Author Comment

    so you mean there is no way to store google charts as image on the system ??
    LVL 11

    Accepted Solution


    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


    Author Comment

    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
    LVL 11

    Expert Comment



    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

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    One of the biggest challenges facing freelancers is balancing multiple projects and deadlines. Organizational skills and time management are key to keeping up with projects and staying on track. Luckily, we’ve curated seven tools to help you focus o…
    Surprisingly, there is a lot to Gym battles, and I thought it would be helpful to share knowledge about all the ins and outs of this feature!
    Introduction to GIMP:  GNU Image Manipulation Program. It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now