Finally I found a solution.
First It is necessary to install xvfb:
sudo apt-get install xvfb
After this it is necessary to run wkhtmltopdf inside the xvfb in order to have a graphic interface:
xvfb-run --server-args="-screen 0, 1024x768x24" wkhtmltopdf --use-xserver file1.html file2.pdf
It is also posible to execute without specifying the server args:
xvfb-run wkhtmltopdf --use-xserver file1.html file2.pdf