PDFTK 库缺少 Apache Common Lib

PDFTK 库缺少 Apache Common Lib

我按照以下说明在 Ubuntu 18.04 上设置了 pdftk:

sudo add-apt-repository ppa:malteworld/ppa
sudo apt update
sudo apt install pdftk

取自之前问过的Askubuntu 问题。我使用 Node 的包装器 Scissors.js 构建了一个快速应用程序来操作多个 PDF。它在我的 Mac 上运行良好,但在 Ubuntu Server 上测试代码时,我在尝试编辑 PDF 时遇到以下错误。

我是否设置了错误的 pdftk repo?

06-08 23:22:10.383: pdftk: Unhandled Java Exception in create_output():
06-08 23:22:10.384: pdftk: 
06-08 23:22:10.385: pdftk: java.lang.NoClassDefFoundError: org/apache/commons/lang3/StringEscapeUtils
06-08 23:22:10.390: pdftk: 
06-08 23:22:10.391: pdftk:  at com.gitlab.pdftk_java.report.OutputXmlString(report.java:61)
06-08 23:22:10.392: pdftk: 
06-08 23:22:10.392: pdftk:  at com.gitlab.pdftk_java.report.OutputPdfName(report.java:92)
06-08 23:22:10.393: pdftk: 
06-08 23:22:10.394: pdftk:  at com.gitlab.pdftk_java.report.ReportInfo(report.java:810)
06-08 23:22:10.395: pdftk: 
06-08 23:22:10.395: pdftk:  at com.gitlab.pdftk_java.report.ReportOnPdf(report.java:964)
06-08 23:22:10.396: pdftk: 
06-08 23:22:10.397: pdftk:  at com.gitlab.pdftk_java.TK_Session.create_output(TK_Session.java:3365)
06-08 23:22:10.397: pdftk: 
06-08 23:22:10.398: pdftk:  at com.gitlab.pdftk_java.pdftk.main(pdftk.java:177)
06-08 23:22:10.398: pdftk: 
06-08 23:22:10.399: pdftk: Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang3.StringEscapeUtils
06-08 23:22:10.400: pdftk: 
06-08 23:22:10.401: pdftk:  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
06-08 23:22:10.401: pdftk: 
06-08 23:22:10.402: pdftk:  at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
06-08 23:22:10.402: pdftk: 
06-08 23:22:10.403: pdftk:  at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
06-08 23:22:10.403: pdftk: 
06-08 23:22:10.404: pdftk:  ... 6 more
06-08 23:22:10.404: pdftk: 
06-08 23:22:10.419: Error: PDF does not contain page number data.
     at BufferStream.<anonymous> (/home/cocatalyst/repo/workflow/node_modules/scissors/scissors.js:634:14)
     at emitNone (events.js:106:13)
     at BufferStream.emit (events.js:208:7)
     at BufferStream.end (/home/cocatalyst/repo/workflow/node_modules/bufferstream/lib/buffer-stream.js:292:14)
     at Stream.onend (internal/streams/legacy.js:44:10)
     at emitNone (events.js:111:20)
     at Stream.emit (events.js:208:7)
     at emitNone (events.js:111:20)
     at Socket.emit (events.js:208:7)
     at endReadableNT (_stream_readable.js:1064:12)

答案1

我使用了以下命令并且能够重新安装 pdftk 而不存在此库错误:

cd /tmp
# download packages
wget http://mirrors.kernel.org/ubuntu/pool/main/g/gcc-6/libgcj17_6.4.0-8ubuntu1_amd64.deb \
    http://mirrors.kernel.org/ubuntu/pool/main/g/gcc-defaults/libgcj-common_6.4-3ubuntu1_all.deb \
    http://mirrors.kernel.org/ubuntu/pool/universe/p/pdftk/pdftk_2.02-4build1_amd64.deb \
    http://mirrors.kernel.org/ubuntu/pool/universe/p/pdftk/pdftk-dbg_2.02-4build1_amd64.deb 
echo -e "Packages for pdftk downloaded\n\n"
# install packages 
echo -e "\n\n Installing pdftk: \n\n"
sudo apt-get install ./libgcj17_6.4.0-8ubuntu1_amd64.deb \
    ./libgcj-common_6.4-3ubuntu1_all.deb \
    ./pdftk_2.02-4build1_amd64.deb \
    ./pdftk-dbg_2.02-4build1_amd64.deb
echo -e "\n\n pdftk installed\n"
echo -e "   try it in shell with: > pdftk \n"
# delete deb files in /tmp directory
rm ./libgcj17_6.4.0-8ubuntu1_amd64.deb
rm ./libgcj-common_6.4-3ubuntu1_all.deb
rm ./pdftk_2.02-4build1_amd64.deb
rm ./pdftk-dbg_2.02-4build1_amd64.deb

答案2

下面的包装脚本为我解决了这个问题(到目前为止,可能需要更多的库):

#!/bin/bash
/usr/bin/java -cp /usr/share/java/commons-lang3.jar:/usr/local/bin/pdftk.jar pdftk "$@"

由于我没有进一步关注或验证的原因,使用 java -jar 运行应用程序时,classpath(-cp)选项似乎不起作用

您可能需要调整路径到正确的位置。

问候

伊沃

相关内容