Question

I am developing a small project for automated report generation for that purpose I am developing some HTML wich I convert to pdf using wkhtmltopdf.

I developed a solution using the windows version and I got into a trouble when migrating to Linux.

When migrated to Linux the charts I was generating with javaScript where not rendered properly, after doing some research i found out that the solucion was to use wkhtmltopdf --use-xserver option, i tried it on the terminal and it worked perfectly.

Here is where my problem comes:

I can use the --use-xserver option with my user and the root user without any problem, but when my app uses "tomcat" user to execute the wkhtmltopdf with --use-xserver option it gives the following error:

No protocol specified.
Wkhtmltopdf: Cannot conect to X server :0.0

I have tried to modify the permissions and the ownership of the wkhtmltopdf executable to tomcat user but still it works with the other users but not with "tomcat".

I have also tried to set the ownership and group to root root an activate the bit SUID in order to give every other user root permisions to execute it, but still the same.

Any clues??

I am quite lost.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top