Install pdftk on CentOS 7 based shared hosting

I recently tried to automate some PDF autofill tasks with python but faced a problem I never had before. The server it should on run is a shared hosting account on the great hosting platform uberspace and I needed pdftk to automate my task with pypdftk. Since I can’t just use apt install like on my personal Debian based devices or install the rpm package I needed a way to get the binary file of pdftk. Surprisingly they don’t supply this binary anywhere only packages containing it.

I searched for it on Google and luckily I found this tweet by the support team of the aforementioned hosting company. They linked to a forum post which contained the simple answer. I’m reposting it here to maybe help some people having less luck with their Google search because they are using different CentOS 7 shared hosters.

How To

You basically download a rpm package and unpack the contained binary into your home directory. Then you add it to your path.

So let’s get to it.

cd ~
wget https://www.linuxglobal.com/static/blog/pdftk-2.02-1.el7.x86_64.rpm
rpm2cpio pdftk-2.02-1.el7.x86_64.rpm | cpio -idmv
export LD_LIBRARY_PATH=$HOME/usr/lib64
export PATH=$HOME/usr/bin:$PATH

From there on you should have a working pdftk command in your current shell session (which also works for pypdftk). Keep in mind though that this installation is only in your path for this shell session because export statements don’t persist.

Making it persistent

You can either just execute these export commands every time before you use pdftk e.g. with a python start script like this

export LD_LIBRARY_PATH=$HOME/usr/lib64
export PATH=$HOME/usr/bin:$PATH
python app.py

or append it to .*rc files like the .bashrc file. In case you need more details see separate guides like this