PDFtk works on CentOS 7 and RHEL 8!

Installing PDFtk on CentOS/RHEL/Scientific Linux 7

Update: This procedure works in RHEL/Rocky/Alma/Oracle Linux 8 and Amazon Linux 2023!

In the transition to CentOS 7, the GNU compiler for the Java programming language libgcj was discontinued. This is partially due to it being dropped by the GCC suite. As it turns out, shared library linking of libgcj.so.10 from CentOS 6 is binary compatible with PDFtk. We use PDFtk in our office for collating documents that have been scanned, and it works great!

After searching online and finding lots of links with various levels of success and server admins having used PDFtk for over a decade, we decided to package it and provide it to the community.

Installation is simple, depending on your architecture:

x86_64

yum localinstall https://www.linuxglobal.com/static/blog/pdftk-2.02-1.el7.x86_64.rpm

i686

yum localinstall https://www.linuxglobal.com/static/blog/pdftk-2.02-1.el7.i686.rpm

After  Updating

If you are reading this article, then you probably just upgraded your system. Now would be a great time to consider security for your application and server infrastructure. There are many services that we offer including support, security, maintenance, monitoring, backups, and live SQL backup replication. We even offer a security hardened hosting environment!

Please let us know if you have any issues with these packages or if we may be of service!

Update: 2017-01-26

Some have asked for the .spec that we are using. Really are we are doing is repacking libgcj.so.10* which we pulled out of CentOS 6 libgcj-4.4.7-17.el6. PDFtk was downloaded as an RPM from their site unmodified except that we converted it to a tar and added libgcj. You may need to edit the spec to make it build on your system, but it works in our build environment: https://www.linuxglobal.com/static/blog/pdftk.spec

-Eric

53 thoughts on “PDFtk works on CentOS 7 and RHEL 8!

  1. I had pdftk working on centos 7 for awhile but somehow my yum update broke. I had used the previous method of:

    rpm -ivh –nodeps libgcj-4.4.7-16.el6.x86_64.rpm
    yum install pdftk-2.02-1.el6.x86_64.rpm

    and it was working. All of a sudden it’s now crashing, giving me these errors. I tried your install and the same thing is happening:

    ./test.sh
    Unhandled Java Exception in create_output():
    java.lang.ClassCastException: pdftk.com.lowagie.text.pdf.PdfNull cannot be cast to pdftk.com.lowagie.text.pdf.PdfDictionary
    at pdftk.com.lowagie.text.pdf.FdfReader.readFields(pdftk)
    at pdftk.com.lowagie.text.pdf.FdfReader.readPdf(pdftk)
    at pdftk.com.lowagie.text.pdf.PdfReader.(pdftk)
    at pdftk.com.lowagie.text.pdf.PdfReader.(pdftk)
    at pdftk.com.lowagie.text.pdf.FdfReader.(pdftk)

    Any idea what’s wrong? I can no longer get pdftk to work. I’m using it for fdf merging.

  2. Here’s another version of the error I get depending upon how I call pdftk whether I do so with an implicit path or not:

    #pdftk test.pdf fill_form test.fdf output testout.pdf

    Unhandled Java Exception in create_output():
    Unhandled Java Exception in main():
    java.lang.NullPointerException
    at gnu.gcj.runtime.NameFinder.lookup(libgcj.so.10)
    at java.lang.Throwable.getStackTrace(libgcj.so.10)
    at java.lang.Throwable.stackTraceString(libgcj.so.10)
    at java.lang.Throwable.printStackTrace(libgcj.so.10)
    at java.lang.Throwable.printStackTrace(libgcj.so.10)

    I have uninstalled libgcj and pdftk and re-installed multiple times.. I’ve been wrestling with this for days and cannot figure out how the system broke… any help is most appreciated

  3. Actually I found what my problem was – pdftk was working properly, although it will throw and error and crash if you try a fill_form command and there’s unbalanced parenthesis in any of the field values.

  4. Thank you so much! In May-June I had scoured the Internet for a solution for Fedora 28. Wasn’t aware you people had looked into it in August. Very glad you did.

  5. Still very useful even in 2019. I hope you will do a version for Centos 8.0 as well as soon as it is released. If there was a Donate button I definitely would.

  6. Thanks so much! FWIW, it looks like this works for RHEL 6 and RHEL 8 as well. So, if you work on servers with various RHEL distros, you can just use this one command on all.

  7. Quick shout out on this post. It helped me help a local non-profit. Just goes to show you that you never know how sharing knowledge will touch and affect others.

  8. Thank you. I got this to work on a shared server on BlueHost. They upgraded me to CentOS7, which broke pdftk for me. When I called they said it wasn’t possible to install on CentOS7.

    To make it work I renamed pdftk to pdftk.target. I then created a script I named pdftk to point to the pdftk.target which has the path to the libgcj.so.10 file.

    #!/bin/bash
    export PATH=~/usr/bin:$PATH;
    export LD_LIBRARY_PATH=~/lib:~/usr/lib64:$LD_LIBRARY_PATH;
    ~/usr/bin/pdftk.target “$@”

    • Hi Gardiner,
      I’m also using shared hosting on Bluehost but I have not been able to get pdftk installed. Any assistance you can provide would be greatly appreciated. Thanks

  9. pdftk on CentOS 8 ? Just rpm -ivh pdftk-2.02-1.el7.x86_64.rpm

    After install, you will have pdftk also working in CentOS 8 (although the RPM is for CentOS 7…).

    Thank you for saving my day upgrading from CentOS 7 to CentOS 8.

  10. It is 2022 and it still helped me. The pdftk-java provided with my CentOS 7.9 took 2.5 minutes for a job instead of 34 seconds as it is the case with the gcj-Version.

    T H A N K Y O U

  11. Thank you so much for your fix; I was able to get pdftk working on my CentOS box in a situation where I had no convenient alternative.

  12. First, thank you! This worked seamlessly on Amazon Linux 2023, so wow! Second, I’m new to building packages (Brand new). I’d be curious if you had a detailed step by step process of how you all put this together. I have an application that’s depended on pdftk since 2011 and it’d be great to have the knowledge of how to begin piecing something like this together myself if necessary. I most recently had to build wkhtmltopdf, which was itself a feat.

    • Hi John, I’m glad it worked! The `pdftk` package depends on the ancient GCC GCJ project which was discontinued by RedHat starting in RHEL 7. However, PDFtk links to the .so just fine if you copy the old CentOS 6 library, so we just packaged the original CentOS 6 PDFtk with its `libgcj.so.10` library dependency into the same RPM. Here is the spec: https://www.linuxglobal.com/static/blog/pdftk.spec

      -Eric

      • Eric, are you saying that I can simply copy/paste the libgcj.so.10 library from a centos server to say an Amazon Linux server and then build pdftk from there? If that’s the case, does it need to exist in /lib64 or /usr/lib64 or both? Also, why do we have both libgcj.so.10 and libgcj.so.10.0.0?

        – John

        • Thats about right.

          `ldd pdftk` paints the picture of what is needed, this is what it looks like here:

          ~$ ldd `which pdftk`
          linux-vdso.so.1 => (0x00007ffec07e4000)
          libgcj.so.10 => /lib64/libgcj.so.10 (0x00007fe00f32b000)
          libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fe00f022000)
          libm.so.6 => /lib64/libm.so.6 (0x00007fe00ed1f000)
          libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fe00eb09000)
          libc.so.6 => /lib64/libc.so.6 (0x00007fe00e748000)
          libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fe00e52b000)
          librt.so.1 => /lib64/librt.so.1 (0x00007fe00e323000)
          libdl.so.2 => /lib64/libdl.so.2 (0x00007fe00e11f000)
          libz.so.1 => /lib64/libz.so.1 (0x00007fe00df08000)
          /lib64/ld-linux-x86-64.so.2 (0x00007fe012483000)

          As for why libgcj.so.10.0.0? It is common practice to symlink libraries to specific versions. In this case, the “major” .10 version is a symlink to the more specific minor version .10.0.0:
          ~$ ls -l /lib64/libgcj.so.10*
          lrwxrwxrwx. 1 root root 16 Aug 18 2016 /lib64/libgcj.so.10 -> libgcj.so.10.0.0
          -rwxr-xr-x. 1 root root 49103168 Aug 18 2016 /lib64/libgcj.so.10.0.0

          • Hi Eric, I’m hoping you might be able to help me just a little more – again I’m very new to building, but would love to accomplish this. I’ve spun up an Amazon Linux 2023 instance. I downloaded libgcj.so.10 and libgcj.so.10.0.0 from an existing CentOS 6 server and then copied those into the /lib64/ folder on the AL 2023 instance. Here is where things get dicey for me. I tried to do a build using the pdftk-2.02-1.el6.src.rpm but I’m getting a number of failed dependencies including libgcj which I thought it would pick up. Any advice would be greatly helpful and I really appreciate all the replies.

          • You won’t be rebuilding the .src.rpm, it will never build on newer systems…but the libgcj dependencies will allow it to run. Just install it with something like `rpm -ivh –nodeps –force pdftk-2.02-1.el6.rpm`

Leave a Comment