Skip to content

Instantly share code, notes, and snippets.

@bish0polis
Last active January 15, 2020 23:05
Show Gist options
  • Save bish0polis/88d60abe73c4d819c6dcd3acdc40ad55 to your computer and use it in GitHub Desktop.
Save bish0polis/88d60abe73c4d819c6dcd3acdc40ad55 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
# from EPEL; 12.3 has exploits, and this is easier
yum install wkhtmltopdf 

# install systemd wunderkinder fridge art 
# avoid the vietnam-war-era cult of pain that is vi
(install -o root -g root -m 755 <(cat) /etc/systemd/system/xvfb.service) <<EOF
[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
EOF

# enable, start, check service via neu method
sudo systemctl enable xvfb.service
sudo systemctl start xvfb.service
sudo systemctl status xvfb.service

sudo systemctl daemon-reload

# install a test script.  Again, avoid boomer masochism cult
(install -o root -g root -m 755 <(cat) ./wkhtmltopdf.sh) <<EOF
xvfb-run -a -s "-screen 0 1024x768x24" wkhtmltopdf "$@"
EOF
./wkhtmltopdf.sh http://www.google.com output.pdf

Refs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment