1

There are many JavaScript plugins to plot charts and graphs. For examples, see http://www.queness.com/post/10781/13-chart-and-graph-plotting-javascript-plugins.

I would like to create a chart and convert it to an image. I have experimented with converting them to PDFs with http://code.google.com/p/wkhtmltopdf/ and it is working great. For installation, I used http://www.amberdms.com/?cms=opensource_linux_repositories.

Now, converting to an image. I installed the sister product wkhtmltoimage. amberdms didn't have this in their repo, so I just used a static binary. It coverts simple pages without charts, but when trying a page with a chart, it doesn't include the JavaScript chart in the image, and I get the following errors:

[root@localhost ~]# /usr/bin/wkhtmltoimage-amd64 --load-error-handling ignore http://www.bobo.com/lib/plugins/jqPlot/examples/area.html var/www/html/images/example_amd64.jpg
Loading page (1/2)
QPixmap: Cannot create a QPixmap when no GUI is being used   ] 86%
....
QPixmap: Cannot create a QPixmap when no GUI is being used
Rendering (2/2)
Error: Could not write to output file
Segmentation fault
[root@localhost ~]#

Does anyone have any suggestions?

PS. I am operating Centos 5.8 86x64, and have tried both wkhtmltoimage-i386 and wkhtmltoimage-amd64.

Does anyone have any suggestions?

Thank you

user1032531
  • 24,767
  • 68
  • 217
  • 387

2 Answers2

2

I had the same experience on a project I'm working, depending on your host settings I found two solutions:

1.Using the 'use-xserver' argument like this

    $ ./wkhtmltoimage-amd64 --use-xserver input.html output.jpg
    Loading page (1/2)
    Rendering (2/2)                                                    
    Done

This worked like a charm on my development machine, however my hosting provider doesn't allow me to use that option so I had to dig up on the google code repository for answers which lead me to the next solution.

2.Use a deprecated static version 64 bit or 32 bit

For some reason there seem to be an xserver dependency on the 0.11.0 versions so I used an old version available on the deprecated download section in this case the 0.10.0_rc2 worked great for my project.

Using this option the use-xserver argument is not necessary:

    $ ./wkhtmltoimage-amd64 input.html output.jpg
    Loading page (1/2)
    Rendering (2/2)                                                    
    Done

I hope any of those options works for you.

Aram
  • 21
  • 5
0

Another option would be wrapping your wkhtmltoimage command within a X server instance using xvfb.

sudo apt-get install xvfb
xvfb-run --server-args="-screen 0, 1280x1024x24" wkhtmltopdf --use-xserver --javascript-delay 3000 your-html-file.html test.pdf

For a more detailed information, take a look at: http://blog.hugerepo.com/2013/04/28/what-is-the-qpixma/

João Daniel
  • 8,696
  • 11
  • 41
  • 65