How do I install Pdftk on my server?

Pdftk is a version of iText which has been converted from Java to c++ and rebuilt with a command-line bridge for easy access from PHP applications.

To build pdftk on Redhat / CentOS please follow the below instructions.

ssh [server to install pdftk on]

Now that we are in the server we need to create the directories to store pdftk.

cd /
sudo mkdir extra
cd extra
sudo mkdir src
cd src
sudo wget http://www.pdfhacks.com/pdftk/pdftk-1.41.tar.gz
sudo tar zxvf pdftk-1.41.tar.gz
cd pdftk-1.41/pdftk

Now we need to install the gcj libraries.

sudo yum install java-1.4.2-gcj-compat-devel.i386

The gcc-c++ library doesn't get installed with the gcj package so we will install it now, so we don't get an error halfway through the compile process.

sudo yum install gcc-c++

If you compile the application right now you will receive a warning that tmpnam is dangerous to use and you should use mkstemp.

sudo vi report.cc

Run this from inside VI to do a search and replace for the tmpnam method.

:%s/tmpnam(/mkstemp(/g

Press escape and save the changes with

:wq!

Now that we have all the packages installed, we are going to start compiling pdftk-1.41

from /extra/src/pdftk-1.41/pdftk run the following command

sudo make -f Makefile.RedHat

This will kick off the build process for compiling and converting the java file to c++. This could take SEVERAL minutes to convert iText to c++. Go grab yourself a margarita from our new margarita machine in the break room :).

Now with the pdftk file created we will want to copy it to the /bin directory so that we can run it from anywhere.

sudo cp pdftk /usr/local/bin

Let's make sure the build was successful and run

pdftk --version

Tags:

Linux

Php

Pdftk