beta.blog

Homebrew: Install wkhtmltopdf

by on Feb.12, 2019, under MAC OS X

wkhtmltopdf is an open source (LGPLv3) command line tool to render HTML into PDF using the Qt WebKit rendering engine. There are bindings for various programming/scripting languages, including Java (java-wkhtmltopdf-wrapper), Go (go-wkhtmltopdf) and PHP (phpwkhtmltopdf). What all of these bindings have in common is that they require the native binaries on the system they’re run on.

The project website states that it runs entirely “headless” and does not require a display or display service. According to the following quote found on the downloads page, this is not entirely true – at least for the Linux builds and running one of the recent builds (0.12.5 at the time of this writing) within i.e. a Docker container may cause some trouble:

Please note that the above linux builds are not headless, and will require running under xvfb.

This means that we need a display/display service in order to run the executable and if we’re running it on a server without GUI we’d have to install a virtual frame buffer such as xvfb (X virtual framebuffer) which performs any kind of graphical operations in a virtual memory without showing any screen output.

As far as Homebrew on macOS is concerned we may simply proceed with installing wkhtmltopdf by issuing the following two commands:

brew update
brew cask install wkhtmltopdf

A brew cask is a particular formula in Homebrew installing macOS-apps, fonts, plugins or non-open-source-software. During the installation we’re asked to enter the password and after a successful installation we may simply use wkhtmltopdf:

wkhtmltopdf –version

The resulting output is:

wkhtmltopdf 0.12.5 (with patched qt)

:

Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!