0

My app uses the library https://github.com/wkhtmltopdf/wkhtmltopdf which requires X server. Here's a workaround:

echo -e '#!/bin/bash\nxvfb-run -a --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf -q $*' > /usr/bin/wkhtmltopdf.sh
chmod a+x /usr/bin/wkhtmltopdf.sh
ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
wkhtmltopdf http://www.google.com output.pdf

I've installed xvfb via pacman and followed the steps in the link. However, nothing has changed: it still returns an error

  wkhtmltopdf http://www.google.com output.pdf

===>

 "qt.qpa.screen: QXcbConnection: Could not connect to display :0.0"

And

$ which wkhtmltopdf
/usr/local/bin/wkhtmltopdf
jerry
  • 111
  • 1
  • 3
  • According to the repo you linked, they don't need a display server: `wkhtmltopdf and wkhtmltoimage are command line tools to render HTML into PDF and various image formats using the QT Webkit rendering engine. These run entirely "headless" and do not require a display or display service.` – Sven Feb 27 '18 at 09:54
  • @Sven how will that "no need" fix my error? – jerry Feb 27 '18 at 14:58
  • If the projects website claim they don't need a display server and you still need one, it's likely you are doing something wrong (or better, you use optional functionality that indeed need an display server) and it's a good idea to investigate in this direction... – Sven Feb 27 '18 at 15:03
  • @Sven what am I doing if not investigating? – jerry Feb 27 '18 at 15:27
  • You are investigating how to get it to run with `xvfb`. I suggested that you shouldn't need it and should investigate how to run it without `xvfb`. These are two very different approaches. – Sven Feb 27 '18 at 15:31

1 Answers1

0

You should try to run wkhtmltopdf.sh instead of just wkhtmltopdf. Seems like you are calling the original binary instead of the xvfb wrapper you created.

To make sure which one you are running try to run "which wkhtmltopdf".

Evengard
  • 234
  • 2
  • 11
  • /usr/local/bin/wkhtmltopdf – jerry Feb 27 '18 at 08:36
  • When you run the sh script by the absolute path you get the same result? Tbh I never used xvfb-run, I always started xvfb manually. I would advise to actually try to start xvfb manually and check for possible errors. – Evengard Feb 27 '18 at 08:42
  • You may also try to add to your xvfb-run the flag --error-file=/some/path/to/log/file.txt to check any possible errors in xvfb startup. – Evengard Feb 27 '18 at 09:03