0

I set up pdftk on Ubuntu 18.04 using the following instructions:

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

taken from a previously asked Askubuntu question. I built a quick app to manipulate several PDFs using the wrapper Scissors.js for Node. It works perfectly on my Mac, but testing the code on Ubuntu Server, I get caught with the following error trying to edit the PDFs.

Did I set up the wrong repo of pdftk?

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)

2 Answers2

1

I used this commands and was able to reinstall pdftk without this library bug:

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
0

The folling wrapper script solved the problem for me (so far, more libraries might be needed):

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

For reasons I did not follow or verify any further, the classpath (-cp) option seems to have no effect when running the application with java -jar

You probably will need to adjust the paths to their correct locations.

Regards

Ivo