After searching and searching, and trying many different things, I finally got it to work by improvising and hacking away. I am using the Linux 64-bit binary version 0.12.0 available at wkhtmltopdf downloads page on an Ubuntu server. Please note that this article does not cover how to install wkhtmltopdf.
That is the only argument you have to change. Below follows my template file used for generating the charts.
When the library is ready, the drawCharts function is invoked. This is simply a function that I made because for my own use case, I need to draw several different charts. So all this function does is call other functions that each draw a chart. You could just as well draw your chart directly in the drawCharts function if you prefer; in other words, you are free to choose how to go about it.
The drawAccountImpressions function is just an example of how to create a line chart. There is nothing in this function that is special for wkhtmltopdf, so you can use the code examples from the Google Visualization API.
All there is left to do is to invoke wkhtmltopdf to generate your PDF, be it on the command line or through a wrapper library such as Snappy for PHP.
I hope this article has helped you save you the hours of searching and experimenting that I went through to figure out a solution. I wish you the best of luck!
Learn Laravel today!
Take an online course and learn the most popular PHP framework!
Here is what is covered:
- Laravel basics (routing, controllers, blade templating, etc.)
- Working with databases (including Eloquent ORM and raw SQL)
- Forms and validation
- ... and much more!