Friday, March 2, 2012

Webkit reports in a X-less server


If you try to run webkit reports in linux system without an X-server (no system GUI), you will probably get error message. This can be caused by the wkhtmltopdf library, used by Webkit report to convert HTML into PDF, because needs to use an X-server to do the conversion.
To can confirm if this is your problem with this:
# echo test>in.txt; wkhtmltopdf in.txt out.pdf
wkhtmltopdf: cannot connect to X server

A workaround to this is to install the static version of the wkhtmltopdf library, (more details  info on ). The procedure, using a root account, is this:
# apt-get update
# apt-get remove wkhtmltopdf
# apt-get install openssl build-essential xorg libssl-dev
# cd /tmp
# wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2 
# tar xvjf  wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2
# chown root:root wkhtmltopdf-i386
# mv wkhtmltopdf-i386 /usr/bin/wkhtmltopdf
# rm wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2

Now test it again. You should get this output:
# echo test>in.txt; wkhtmltopdf in.txt out.pdf
Loading pages (1/6)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

Remeber you must provide the path to wkhtmltopdf in the Company form (at Settings/Administration » Companies » Companies » Webkit tab » Webkit Executable Path). Usualy it's /usr/bin/wkhtmltopdf, but you can confirm that with this command:
# which wkhtmltopdf