[英]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 do.我正在使用 Linux 服务器并且正在尝试安装 Pdftk,但是我在尝试弄清楚究竟要做什么时遇到了问题。
I found the following documentation on how to install it, but they refer mostly to installing it on the local Windows machine.我找到了以下有关如何安装它的文档,但它们主要是指在本地 Windows 机器上安装它。
They are: http://www.andrewheiss.com/blog/2009/07/29/installing-pdftk-php/它们是: http : //www.andrewheiss.com/blog/2009/07/29/installing-pdftk-php/
http://www.accesspdf.com/pdftk/#packages 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 吗?
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. Pdftk 是 iText 的一个版本,它已从 Java 转换为 C++,并使用命令行桥重新构建,以便从 PHP 应用程序轻松访问。
To build pdftk on Redhat / CentOS please follow the below instructions.要在 Redhat / CentOS 上构建 pdftk,请按照以下说明进行操作。
ssh [server to install pdftk on]
Now that we are in the server we need to create the directories to store pdftk.现在我们在服务器中,我们需要创建目录来存储 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.现在我们需要安装 gcj 库。
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. gcc-c++ 库没有随 gcj 包一起安装,所以我们现在就安装它,这样我们就不会在编译过程中途出现错误。
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.如果您现在编译应用程序,您将收到一条警告,指出使用 tmpnam 很危险,您应该使用 mkstemp。
sudo vi report.cc
Run this from inside VI to do a search and replace for the tmpnam method.从 VI 内部运行它以搜索并替换 tmpnam 方法。
:%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现在我们已经安装了所有的包,我们将开始编译 pdftk-1.41
from /extra/src/pdftk-1.41/pdftk run the following command从 /extra/src/pdftk-1.41/pdftk 运行以下命令
sudo make -f Makefile.RedHat
This will kick off the build process for compiling and converting the java file to c++.这将启动编译 Java 文件并将其转换为 C++ 的构建过程。 This could take SEVERAL minutes to convert iText to c++.
这可能需要几分钟才能将 iText 转换为 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.现在创建 pdftk 文件后,我们要将其复制到 /bin 目录,以便我们可以从任何地方运行它。
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.到 2020 年,现在情况有所不同。 CentOS 6 is stepping out and pdftk can only supportCentOS 5/6 .
CentOS 6 即将退出,pdftk 只能支持CentOS 5/6 。 GCJ on CentOS 7 is removed, so installing from source is not easy too.
CentOS 7 上的 GCJ 已被删除,因此从源代码安装也不容易。 But we have docker now:
但是我们现在有了 docker:
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
然后使用
docker build . -t pdftk
docker build . -t pdftk
and run as: docker build . -t pdftk
并运行为:
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.如果幸运的话,上面的示例可以修复丢失了十几 KB 数据的 pdf 文件。
到 2021 年,有pdftk-java :原始基于 GCJ 的 PDFtk 到 Java 的端口, 目前正在向Fedora 33+ 和 EPEL 7+(后者用于 CentOS、RHEL 或 Rocky) 的存储库中,允许yum install pdftk-java
成功(一旦包到达稳定的存储库)。
As mentioned by @rsc, pdftk-java will be available for Rocky Linux, but currently (2021.10.28), still cannot install it via yum
.正如@rsc 所提到的, pdftk-java 将可用于 Rocky Linux,但目前(2021.10.28)仍然无法通过
yum
安装它。
Fortunately, there is a built command for x86_64 GNU/Linux systems, which does not require any runtime dependencies .幸运的是,有一个针对 x86_64 GNU/Linux 系统的内置命令,它不需要任何运行时依赖项。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.