Install wkhtmltopdf on Gentoo

Just a little reminder about how wkhtmltopdf and Gentoo.
You’ll need Xvfb otherwise you’ll see pop this error.

$ wkhtmltopdf test.pdf
wkhtmltopdf: cannot connect to X server

Just simply do this:

echo "x11-base/xorg-server minimal xvfb -xorg" >> /etc/portage/package.use
emerge -q wkhtmltopdf xorg-server

Create the init script to launch it:

cat <<EOF > /etc/init.d/Xvfb
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

start() {
ebegin "Starting virtual X frame buffer: Xvfb"
start-stop-daemon --start --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
eend ${?}

stop() {
 ebegin "Stopping virtual X frame buffer: Xvfb"
 start-stop-daemon --stop --pidfile $PIDFILE
 eend ${?}

$ rc-update add Xvfb

And the conf files:

cat <<EOF > /etc/conf.d/Xvfb
XVFBARGS=":100 -screen 0 1600x1200x24 -auth /etc/conf.d/Xvfb.cfg -nolisten tcp"

echo "localhost" > /etc/conf.d/Xvfb.cfg