Thursday, March 29, 2012

If you want to generate pdf from HTML on Ubuntu and try to search the tool for the same, you will find lots of tools for it. But wkhtmltopdf is the best one among them. 

So please follow these steps to install wkhtmltopdf along with qt4 that can convert rich javascript graphs into pdf.

Step 1: First install the dependencies
          sudo apt-get install openssl build-essential xorg libssl-dev libxrender-dev libqt4-dev qt4-dev-tools
Step 2: Install wkhtmltopdf
     sudo apt-get install wkhtmltopdf
Step 3: Test the installation
      wkhtmltopdf http://www.highcharts.com/demo test.pdf
  
If you are using highchart and facing issue related to segmentation fault then try after disabling animation as mentioned 
in the follwoing code:
 
<script type="text/javascript" charset="utf-8">
 
  var chart = new Highcharts.Chart({
      chart: { renderTo: 'container' },
 
      // These make it work nicely with wkhtmltopdf
      plotOptions: { series: { enableMouseTracking: false, shadow: false, animation: false } },
 
      xAxis: { categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct'] },
      series: [{ data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1] }]
 
  });
 
</script>
 
Have fun with wkthltopdf !!!!

No comments:

Post a Comment