php 如何在我的服务器上安装 Pdftk?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3146766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 08:50:36  来源:igfitidea点击:

How do I install Pdftk on my server?

phplinuxpdftk

提问by zeckdude

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 吗?

回答by Bot

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++. This could take SEVERAL minutes to convert iText to c++. Go grab yourself a margarita from our new margarita machine in the break room :).

这将启动编译 Java 文件并将其转换为 C++ 的构建过程。这可能需要几分钟才能将 iText 转换为 C++。去休息室用我们的新玛格丽塔机拿一杯玛格丽塔酒:)。

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

回答by etc-100g

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:

到 2020 年,现在情况有所不同。CentOS 6 即将退出,pdftk 只能支持CentOS 5/6。CentOS 7 上的 GCJ 已被删除,因此从源代码安装也不容易。但是我们现在有了 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 pdftkand 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 文件。