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

发布于 2024-09-07 05:13:05 字数 461 浏览 8 评论 0原文

我正在使用 Linux 服务器并尝试安装 Pdftk,但我在尝试弄清楚到底要做什么时遇到问题。

我找到了以下有关如何安装它的文档,但它们主要指的是在本地 Windows 计算机上安装它。

他们是: http://www.andrewheiss.com/blog/2009/ 07/29/installing-pdftk-php/

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

有人可以帮助我准确理解我需要将哪些文件放置在服务器上的位置,以便我可以参考 pdftk 吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

甚是思念 2024-09-14 05:13:05

Pdftk 是 iText 的一个版本,已从 Java 转换为 C++,并使用命令行桥重新构建,以便从 PHP 应用程序轻松访问。

要在 Redhat / CentOS 上构建 pdftk,请按照以下说明操作。

ssh [server to install pdftk on]

现在我们位于服务器中,我们需要创建目录来存储 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

现在我们需要安装 gcj 库。

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

gcc-c++ 库没有随 gcj 包一起安装,因此我们现在就安装它,这样我们就不会在编译过程中途出现错误。

sudo yum install gcc-c++

如果您现在编译应用程序,您将收到一条警告,指出使用 tmpnam 存在危险,您应该使用 mkstemp。

sudo vi report.cc

从 VI 内部运行此命令来搜索并替换 tmpnam 方法。

:%s/tmpnam(/mkstemp(/g

按 escape 并保存更改

:wq!

现在我们已经安装了所有软件包,我们将开始

从 /extra/src/pdftk-1.41/pdftk 编译 pdftk-1.41 运行以下命令

sudo make -f Makefile.RedHat

这将启动编译和构建过程将java文件转换为c++文件。将 iText 转换为 c++ 可能需要几分钟的时间。去休息室从我们的新玛格丽塔机里拿一杯玛格丽塔吧:)。

现在创建 pdftk 文件后,我们希望将其复制到 /bin 目录,以便我们可以从任何地方运行它。

sudo cp pdftk /usr/local/bin

让我们确保构建成功并运行

pdftk --version

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
谎言 2024-09-14 05:13:05

到了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

然后使用 docker build 进行构建。 -t pdftk 并运行为:

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

如果幸运的话,上面的示例可以修复丢失十几 KB 数据的 pdf 文件。

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.

寂寞美少年 2024-09-14 05:13:05

正如 @rsc 提到的,pdftk-java 将可用于 Rocky Linux,但目前(2021.10.28)仍然无法通过 yum 安装它。

幸运的是,有一个针对 x86_64 GNU/Linux 系统的内置命令,它不需要任何运行时依赖项。所以我们可以按如下方式使用它

# 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 ...

它在具有以下系统信息的服务器中运行良好,

$ 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 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
叫思念不要吵 2024-09-14 05:13:05

截至 2021 年,有 pdftk-java:原始基于 GCJ 的 PDFtk 的端口Java,目前正在发送到存储库的路上对于 Fedora 33+ 和 EPEL 7+(后者适用于 CentOS、RHEL 或 Rocky),允许 yum install pdftk-java 成功(一旦软件包到达稳定存储库)。

编辑: pdftk-java 包从昨天(2021 年 10 月 29 日)开始就位于稳定存储库中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文