How do I install Pdftk on my server?
I am using a Linux Server and am trying to install Pdftk, but I am problems trying to figure out what exactly to d开发者_高级运维o.
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?
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
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.
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
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.
精彩评论