0

I am building a site using CodeIgniter and I'm using jQuery Visualize to generate some charts. Now i need to print those charts into PDF (i'm using TCPDF now) but i couldn't find a way to print the charts (AFAIK jQuery Visualize use Ajax to create canvas from my HTML table so i couldn't print the HTML to PDF).

I found this topic very similar include jquery charts into pdf but i don't wish to capture HTML to image since i'm going to generate many reports in PDF so i'm not going to view them before (the word "capture" sounds to me i need to view it to browser first).

Is there a way? (Hopefully using jQuery Visualize and TCPDF since i already worked on pretty much on those, but if you think that's impossible please suggest me another chart tool). Thank you.

Community
  • 1
  • 1
why.you.and.i
  • 497
  • 8
  • 20
  • Looks like a duplicate to http://stackoverflow.com/questions/1535958/php-data-to-chart-to-image-to-pdf – Homer6 Aug 20 '11 at 17:13

2 Answers2

1

I've actually come across this with TCPDF and had to implement my own chart rendering algorithms for server-side because I couldn't find a good server-side rendering package. Unfortunately, that was closed source and I don't have access to it anymore, but you may have a couple options:

  1. Try to leverage client-side rendering, as you have mentioned. A lot of effort goes into that rendering and if you can get a browser to be triggered automatically, it can use that code to render the image and then place that image into the pdf.
  2. Build your own charting engine in PHP. I might be interested in helping you as I've often run into this (having done it once before already) and I'd be interested in adding it to my open source library (https://github.com/homer6/altumo)

Hope that helps...

Homer6
  • 15,034
  • 11
  • 61
  • 81
  • Sorry for late response, i'm facing a certain deadline so i guess i'll try the work around for now like you suggested on first option. Thank you for your time and help. – why.you.and.i Aug 21 '11 at 12:27
  • FYI... PrinceXML is the best alternative I've found to TCPDF... it's used by google and if you can get an HTML graphing library to generate SVG, you may be able to it working to serve your charting needs. Keep in mind, it does have a hefty license cost, but it's well worth it if you're doing many different layouts of PDFs. See: http://www.princexml.com/doc/7.0/svg/ – Homer6 Aug 21 '11 at 16:46
  • 1
    Thank you for the suggestion. Sadly our project budget is strict. And due to the short times ahead, i decided to change to Google Image Chart and passed the image hyperlink to TCPDF. – why.you.and.i Aug 21 '11 at 20:19
0

Passing the google image chart seems to be the only way to insert a chart into TCPDF.

Something like:

$pdf->Image("http://chart.googleapis.com/chart?cht=r&chxt=y,x&chls=4&chco=E26F1E&chs=580x510&chts=000000,20&chxr=0,0.0,100.0&chd=t:" . $percent[0] . "," . $percent[1] . "," . $percent[2] . "," . $percent[3] . "," . $percent[4] . "," . $percent[5] . "," . $percent[0] . "&chtt=Self+Assesment+Results&chxp=0,0,20,40,60,80,100&chxs=0,000000,12|1,000000,12&chxl=1:|Storage+/+Handling|Dispensing|Contamination+Control|Oil+Analysis|Oil+Sampling|Training+/+Certification&chm=s,E26F1E,0,-1,12,0|s,FFFFFF,0,-1,8,0", 90, 90, 120, 0, 'PNG');
Michael Fever
  • 845
  • 2
  • 8
  • 26
  • Indeed, that's what i ended up with. I was looking for a way to insert JQuery Visualize to TCPDF though, still thank you for the time :) – why.you.and.i Dec 01 '12 at 00:56
  • I found a way for my application. You have to generate the image first then export it to a canvas and then save it, I chose to save it into a database. Start here: http://www.battlehorse.net/page/topics/charts/save_google_charts_as_image.html there is some code you need to change at the top before it will work with the latest version .. if you need more help I can help you. I made a 2-step process for my application .. step 1 generates the image step 2 generates the pdf pulling the image from step 1 out of a mySQL DB – Michael Fever Dec 03 '12 at 21:01
  • Thank you for following up, it is already done, with Google Chart. It's an old project and initially i was looking for a way to use jQuery Visualize since i love the looks of it. – why.you.and.i Dec 11 '12 at 02:36