Skip to content

Instantly share code, notes, and snippets.

@Jabolcnik
Last active November 17, 2022 22:27
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jabolcnik/bfa28516879dd3d062d34f9d9cdf3011 to your computer and use it in GitHub Desktop.
Save Jabolcnik/bfa28516879dd3d062d34f9d9cdf3011 to your computer and use it in GitHub Desktop.
wkhtmltopdf centos 7 headless with xvfb

wkhtmltopdf centos 7 headless with xvfb

Install and run standalone Xvfb

yum install xorg-x11-server-Xvfb
yum install xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi
wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm
rpm -ivh wkhtmltox-0.12.2.1_linux-centos7-amd64.rpm

vim xvfb.service
cp xvfb.service /etc/systemd/system/xvfb.service
sudo systemctl enable xvfb.service
sudo systemctl start xvfb.service
sudo systemctl status xvfb.service

sudo systemctl daemon-reload

vim wkhtmltopdf.sh
chmod a+rx wkhtmltopdf.sh
./wkhtmltopdf.sh http://www.google.com output.pdf

At the end edit sudo nano /usr/bin/xvfb-run script and comment out the section

if ! which xauth >/dev/null; then
error “xauth command not found”
    exit 3
fi

Refs

xvfb-run -a -s "-screen 0 1024x768x24" wkhtmltopdf "$@"
[Unit]
Description=Virtual Frame Buffer X Server
After=network.target
[Service]
ExecStart=/usr/bin/Xvfb :42 -screen 0 1024x768x24 -ac +extension GLX +render -noreset
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment