The following code uses wkhtmltopdf which you need to install on your web host. On a typical Debian host, you need to apt-get install wkhtmltopdf. This installs a binary and all the required libraries. The problem is that this version needs an X11 server in order to work, which you don’t have when using it on your website. In addition to a regular installation, you need to install a statically compiled binary which has been compiled with a patched version of Qt and no longer requires an X11 server. At least that was the situation in 2013.

The first piece of code puts the PDF button on the Administration page.