How do I install Pdftk on my server?
Asked Answered
S

4

8

I am using a Linux Server and am trying to install Pdftk, but I am problems trying to figure out what exactly to do.

I found the following documentation on how to install it, but they refer mostly to installing it on the local Windows machine.

They are: http://www.andrewheiss.com/blog/2009/07/29/installing-pdftk-php/

http://www.accesspdf.com/pdftk/#packages

Can someone help me unserstand exactly what files I need to place where on my server so I can refer to pdftk?

Symmetrize answered 30/6, 2010 at 5:49 Comment(2)
What distribution and version?Mongeau
The first instructions you linked to do contain linux instructions... First step would probably be unzipping the tarball into a directory in /var/www/ (or similar, depends)...Countermove
U
15

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
Unending answered 8/9, 2010 at 19:7 Comment(6)
i have followed your instructions to install pdftk ...and pdftk --version runs okayDanube
but i cant make it run through php..why?Danube
I am trying to follow your directions to install PDFTK on my VPS. I get to sudo yum install java-1.4.2-gcj-compat-devel.i386. Once I execute that command, I get this a a response: Setting up Install Process Setting up repositories imhbase 100% |=========================| 951 B 00:00 serverdensity 100% |=========================| 951 B 00:00 not using ftp, http[s], or file for repos, skipping - 4 is not a valid release or hasnt been released yet Cannot find a valid baseurl for repo: update Error: Cannot find a valid baseurl for repo: updateZsa
Hi, thanks for the detailed instructions. I needed to take one additional step: Edit the Makefile.Redhat file, and change export VERSUFF= to export VERSUFF="". Prior to that make would just drop out without doing any work.Intestinal
Works for version 1.45 on Centos 6.3 if you change wget to pdflabs.com/tools/pdftk-the-pdf-toolkit//pdftk-1.45-src.zipIllyrian
For CentOS there is version in extra repository. Explained here: forums.cpanel.net/f5/…Toothlike
B
1

As of 2020, things are different now. CentOS 6 is stepping out and pdftk can only support CentOS 5/6. GCJ on CentOS 7 is removed, so installing from source is not easy too. But we have docker now:

FROM centos:centos6
RUN yum install -y https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk-2.02-1.el6.x86_64.rpm

Then build with docker build . -t pdftk and run as:

docker run -it --rm -v $PWD:/data --workdir /data pdftk pdftk ./input.pdf output ./output.pdf

The example above can repair a pdf file missing a dozen of KB of data if you are lucky.

Bandur answered 12/5, 2020 at 21:0 Comment(0)
F
1

As of 2021, there is pdftk-java: A port of the original GCJ-based PDFtk to Java, which is currently on the way to the repositories for Fedora 33+ and EPEL 7+ (latter for CentOS, RHEL or Rocky), allowing yum install pdftk-java to succeed (once the package reached the stable repositories).

Edit: The pdftk-java package is in the stable repositories since yesterday, 2021-10-29.

Fang answered 20/10, 2021 at 20:42 Comment(0)
M
1

As mentioned by @rsc, pdftk-java will be available for Rocky Linux, but currently (2021.10.28), still cannot install it via yum.

Fortunately, there is a built command for x86_64 GNU/Linux systems, which does not require any runtime dependencies. So we can use it as follows

# the version number might be updated, check https://gitlab.com/pdftk-java/pdftk
wget https://gitlab.com/pdftk-java/pdftk/-/jobs/1527259632/artifacts/raw/build/native-image/pdftk
chmod +x pdftk
./pdftk ...

It works well in the server with the following system info,

$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: Rocky
Description:    Rocky Linux release 8.4 (Green Obsidian)
Release:    8.4
Codename:   GreenObsidian
Miguelmiguela answered 28/10, 2021 at 14:42 Comment(1)
The pdftk-java package is in the stable repositories since yesterday, 2021-10-29. Given it receives updates via a regular dnf update, the RPM package should be preferred over static builds being manually downloaded.Fang

© 2022 - 2024 — McMap. All rights reserved.