1

I am using pdftk library in ubuntu 16.04 to merge several pdf. Everything is OK, when I installed a SSL certificate I get this error :

Error: Unexpected Exception in open_reader()
java.lang.RuntimeException: java.lang.RuntimeException: error instantiating 
default socket factory: java.security.KeyManagementException: 
java.security.KeyStoreException: java.io.FileNotFoundException: 
/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre/lib/security/cacerts (No such file or 
directory)
at javax.net.ssl.SSLSocketFactory$ErrorSocketFactory.createSocket(libgcj.so.16)
at gnu.java.net.protocol.http.HTTPConnection.getSocket(libgcj.so.16)
at gnu.java.net.protocol.http.HTTPConnection.getOutputStream(libgcj.so.16)
at gnu.java.net.protocol.http.Request.dispatch(libgcj.so.16)
at gnu.java.net.protocol.http.HTTPURLConnection.connect(libgcj.so.16)
at gnu.java.net.protocol.http.HTTPURLConnection.getInputStream(libgcj.so.16)
at java.net.URL.openStream(libgcj.so.16)
at pdftk.com.lowagie.text.pdf.RandomAccessFileOrArray.<init>(pdftk)
at pdftk.com.lowagie.text.pdf.PRTokeniser.<init>(pdftk)
at pdftk.com.lowagie.text.pdf.PdfReader.<init>(pdftk)
at pdftk.com.lowagie.text.pdf.PdfReader.<init>(pdftk)
Caused by: java.lang.RuntimeException: error instantiating default socket 
factory: java.security.KeyManagementException: java.security.KeyStoreException: 
java.io.FileNotFoundException: /usr/lib/jvm/java-1.5.0-gcj-5- 
amd64/jre/lib/security/cacerts (No such file or directory)
at javax.net.ssl.SSLSocketFactory.getDefault(libgcj.so.16)
at javax.net.ssl.HttpsURLConnection.getDefaultSSLSocketFactory(libgcj.so.16)
at javax.net.ssl.HttpsURLConnection.getSSLSocketFactory(libgcj.so.16)

after several research I find that the problem comes from the https link. When I use a link from a pdf file whith https It doesn't work For example :

sudo pdftk https://www.fifa.com/mm/document/fanfest/magazine/magazine09-06p.3en_3465.pdf output 1805.pdf

Could you please help me fix this error.

Mohamed
  • 45
  • 1
  • 6

2 Answers2

8

I had the same issue and played around with switching between installed java versions, but with no effect.

when searching further I found this site: https://wilransz.com/pdftk-on-ubuntu-18-04/

Creating a symlink like this

sudo ln -s /snap/pdftk/current/usr/bin/pdftk /usr/bin/pdftk

fixed the issue!

DrT
  • 81
  • 1
  • 6
  • 2
    Under my Kubuntu (18.04 LTS) it doesn't work due to snap rights to write on the FS. It works only in the file is in $HOME. – Hastur Sep 08 '20 at 13:39
3

The problem is that you have an incomplete or broken GCJ Java installation. The "cacerts" file that should be present at ...

/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre/lib/security/cacerts

... is missing. According to Ubuntu package search, in Ubuntu 16.04, the file should be part of the libgcj16 package. So try installing that package using apt.


The real issue is that the PDFTK is relying on the old GCJ Java toolchain. GCJ has barely been maintained, and has finally been deprecated and dropped from the GCC code base ... as of GCC 7.1.

The GCJ toolchain was removed from RedHat in RHEL 7 (back in 2011!), and it was finally removed from Ubuntu in Ubuntu 18.04.

Unfortunately the maintainers for PDFTK have not made available a port for Oracle / OpenJDK versions of Java. In fact, there don't appear to have been changes in the upstream distribution from PDFLabs since 2014 ... so maybe you should be looking for an alternative.

(Or use a fork: see https://askubuntu.com/questions/1028522/how-can-i-install-pdftk-in-ubuntu-18-04-bionic. However, think carefully about the various problems that might arise if you depend on an unofficial / unsupported fork of a "dead" project.)


See also:

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216