Trancefussion Tell me this is real. Are you …?

November 4, 2009

Pdftk not working on Ubuntu 9.10 – Fix

Filed under: Technology — Tags: — liam @ 7:07 pm

NOTE: This patch is no longer required for Ubuntu 10.04, as this problem seems to have been fixed. If you notice any errors, and you’d like to contribute, please leave a comment.

I maintain several websites where this utility is used to produce PDFs. I took the bold decision to upgrade one of my production servers to 9.10, regardless of the risks. Reason being that I rather learn to operate a new operative system, for whenever it happens that a client decides to commit the same mistake bold decisions like me.

So anyway, after the update to 9.10, Pdftk stopped working. I wasn’t really sure what the problem was after looking at the logs, so I googled around for an answer. The error I was getting was this message, whenever I tried to make a PDF with Pdftk:

glyphlist.txt loading error: glyphlist.txt not found as resource. (It must exist as resource in the package com.lowagie.text.pdf.fonts)
Helvetica not found as resource. (The *.afm files must exist as resources in the package com.lowagie.text.pdf.fonts)
Unhandled Java Exception:
ExceptionConverter: com.lowagie.text.DocumentException: Helvetica not found as resource. (The *.afm files must exist as resources in the package com.lowagie.text.pdf.fonts)
at com.lowagie.text.pdf.Type1Font.(itext-2.1.5.jar.so)
at com.lowagie.text.pdf.BaseFont.createFont(itext-2.1.5.jar.so)
at com.lowagie.text.pdf.BaseFont.createFont(itext-2.1.5.jar.so)
at com.lowagie.text.pdf.BaseFont.createFont(itext-2.1.5.jar.so)
at com.lowagie.text.pdf.DocumentFont.doType1TT(itext-2.1.5.jar.so)
at com.lowagie.text.pdf.DocumentFont.(itext-2.1.5.jar.so)
at com.lowagie.text.pdf.AcroFields.decodeGenericDictionary(itext-2.1.5.jar.so)
at com.lowagie.text.pdf.AcroFields.getAppearance(itext-2.1.5.jar.so)
at com.lowagie.text.pdf.AcroFields.setField(itext-2.1.5.jar.so)
at com.lowagie.text.pdf.AcroFields.setField(itext-2.1.5.jar.so)
at com.lowagie.text.pdf.AcroFields.setFields(itext-2.1.5.jar.so)

Basically, what this error is saying is that the itext-2.1.5 library cannot be found, even though it’s already installed. It took me quite a while to understand this exactly, apparently this error is due to a hardcoded line that wasn’t changed in the newer builds, or something to that effect. So the solution is to tell Pdftk where to find it.

I spotted the solution in this URL but the explanation was a bit obscure. The person answering there says we should edit certain files in the patches, the problem is that for common or not so-savvy people (like me) that line wasn’t quite clear enough.

So I went and investigated a bit, until I finally figured it out. Here’s the solution:

IMPORTANT NOTE

Per suggestion of people that have read my post, I’m including the next commands. These steps weren’t necessary for my installation, but some of you might need it.

apt-get install dpkg-dev
This installs the dpkg-source for source-manhandling done in the downloading step

apt-get build-dep pdftk
This ensures all the necessary pre-reqs are installed for the compilation step

Obtain the source from the Ubuntu 9.10 repositories

For this, goto a safe directory where you can work the files, it can be anywhere as long as you remember where it is. Once there, you get the source with this command:

apt-get source pdftk

This will download the source to your current directory and make it available for you to manipulate.

Applying the “fix”

Now you gotta apply the solution mentioned in the other page I mentioned earlier, which is to edit a file called set_classpath and it’s included inside yourworkingdir/pdftk-1.41+dfsg/debian/patches. To do this, use:

nano pdftk-1.41+dfsg/debian/patches/set_classpath

This is if you’re in a terminal. Either use nano or your favourite text editor.

Next, you gotta add the itext library to this file, which would usually look like this:

Description: introduce path to bcprov.jar and bcmail.jar
Author: Johann Felix Soden

--- a/pdftk/pdftk.cc
+++ b/pdftk/pdftk.cc
@@ -2655,6 +2655,10 @@
bool synopsis_b= ( argc== 1 );
int ret_val= 0; // default: no error

+ // set classpath:
+ static char my_classpath[]="CLASSPATH=/usr/share/java/bcprov.jar:/usr/share/java/bcmail.jar";
+ putenv(my_classpath);
+
for( int ii= 1; ii< argc; ++ii ) {
version_b=
(version_b ||

Notice the part where it says CLASSPATH? That’s where we have to add the itext library, by switching the line to look like this:

+ static char my_classpath[]="CLASSPATH=/usr/share/java/bcprov.jar:/usr/share/java/bcmail.jar:/usr/share/java/itext.jar";

Notice the packages are separated by colons “:”. After doing this, you gotta compile it with the next line:

apt-get -b source pdftk

NOTE: Make sure you’re NOT in another directory when using this command, you must be in the same root directory you used to download the source, otherwise you gonna end up with exactly the same faulty pdftk installation.

After the compilation process is complete, you gonna have a file named pdftk_1.41+dfsg-1_i386.deb (depending on your architecture you might have an slightly different one) which we gonna use to install the fixed pdftk package. To do this, use the next command:

dpkg -i pdftk_1.41+dfsg-1_i386.deb

After doing this, pdftk will get installed in its adequate place, and voila! Problem Solved.

If you got any questions feel free to drop a message, I’ll respond as soon as I can. Also, read the comments, a few have contributed with extra steps for other applications, as its the case with Vanguard.

19 Comments »

  1. EXCELLENT! I searched high and low for a solution to this exact problem … and all of the Nabble and Bugzilla posts were too cryptic for me to decipher — this post was exactly what I needed. PROBLEM SOLVED. Thanks again.

    Comment by Jeff — November 17, 2009 @ 11:30 am

  2. You’re welcome πŸ˜€

    Comment by liam — November 18, 2009 @ 7:50 am

  3. Thanks for this, it was exactly what I was looking for when I made the same Ubuntu upgrade, though I ran into the following issue:

    dpkg-checkbuilddeps: Unmet build dependencies: debhelper (>= 7.0.50~) quilt (>= 0.46-7~) gcj
    dpkg-buildpackage: warning: Build dependencies/conflicts unsatisfied; aborting.

    Which was solved by installing the debhelper, quilt and gcj packages

    Comment by James Brooks — January 3, 2010 @ 11:04 pm

  4. wow, perfect! thank you a lot!

    Comment by m4lvin — January 18, 2010 @ 4:54 am

  5. Thanks a lot! Works perfect!

    Comment by Martanus — January 23, 2010 @ 5:48 pm

  6. Works perfect, small suggestion to ensure apt doesn’t update and overwrite this.

    sudo echo pdftk hold | sudo dpkg –set-selections

    or run as root without sudo.

    Comment by Nick E. — February 4, 2010 @ 2:41 pm

  7. Oh, this is super! And I can finally get my tax forms from Vanguard in PDF format, having just discovered the pdftk solution right before having it fail and then finding this post. πŸ™‚

    Looking at the several recent comments here, I’m wondering how many other people might be suffering at the hands of Vanguard. I don’t know why they can’t just do this simple step for us.

    For me, I also had to apt-get debhelper, quilt, and gcj to make this work, but it was very straight-forward, and I really appreciate your easy-to-follow instructions. In theory, I should be able to work this stuff out also from the bread crumbs out there, but usually can’t be bothered, so this is just wonderful.

    Thank you so much!

    Comment by Scott Carpenter — February 7, 2010 @ 3:57 pm

  8. The problem is they don’t know, they’d just assume you got a working installation of PDFTK.

    Look at when I made the post, as far as I know they haven’t fixed the bug on Ubuntu, even though it’s confirmed and its solution been found. I’m sure they got a good excuse, but they won’t implement it.

    So, I don’t know. I’m still waiting for them to fix it, it’d be nice having it working out of the box, but I guess we’d have to wait for a major release of either ubuntu (April is near), or pdftk.

    Comment by liam — February 7, 2010 @ 4:32 pm

  9. Hi, liam — I was referring more to Vanguard assuming you’re using Windows and Adobe and that you’ll be able to view the FDF that way. But even when I’ve had a Windows installation to experiment on, FDF seemed kind of flaky and I didn’t see a way to save as a proper PDF. I just used my comment as an excuse to rant about Vanguard. πŸ™‚

    (And they have other annoyances like having their web page complain that Adobe is required to view PDF and they don’t detect the Adobe Reader on my system, instead of just minding their own business and letting me use whatever PDF reader I want to!) πŸ˜‰

    But really, that’s neither here nor there. It would be nice not to have to do this workaround, but with the need for it, again thank you for spelling it out. I feel so empowered now that I can save these files as PDF for my records!

    Comment by Scott Carpenter — February 7, 2010 @ 4:48 pm

  10. Thanks 1E+06! Saw the bug report, but lacked the patch-fu…

    *f*

    Comment by Fred Buhl — February 9, 2010 @ 7:56 am

  11. I also had to install quilt and gcj. After that, everything worked like a charm. Thanks to everyone who contributed for your help.

    Comment by Mark M — February 10, 2010 @ 4:19 pm

  12. This article is a TREMENDOUS help. As you’ve probably noticed a number of us are having to deal with institutions *cough*Vanguard*cough* that give tax information as FDF files instead of doing the work of building the PDF themselves (which as you show at the top, is trivial and would save us all some headache).

    Anyway, I had two suggestions for the guide. People doing this from many distros will want to run two commands before they start:

    apt-get install dpkg-dev
    This installs the dpkg-source for source-manhandling done in the downloading step

    apt-get build-dep pdftk
    This ensures all the necessary pre-reqs are installed for the compilation step

    Thanks again!

    Comment by Drew S. — February 15, 2010 @ 11:24 pm

  13. Awesome! thanks a lot! I read the bug report and the solution for it, but i didn’t really know how to implement the solution. this was very helpful. thanks again!

    suggestion, though: apt-get build-dep pdftk did help me with building the package, but there were still unmet dependencies after i installed the patched pdftk using dpkg. to fix those unmet dependencies i did the standard:

    apt-get -f install

    hope this might help others like me.

    Comment by mooman — March 8, 2010 @ 12:15 pm

  14. Awesome – a life saver!

    Thanks…

    Comment by Anders Vinther — March 10, 2010 @ 12:23 pm

  15. Thanks for the nice explanation liam. It worked in first try

    Comment by Bojan — March 10, 2010 @ 2:41 pm

  16. They appear to have updated pdftk in 10.04, the patching is no longer necessary. I’m unsure if the package was updated in 9.10.

    Comment by Nick — May 28, 2010 @ 11:54 am

  17. Excellent news, Nick. Thanks for the tip.

    I haven’t installed 10.04 yet as I’m still fearing more things will break, but I will update the post to let everyone know 10.04 no longer requires this work around.

    Comment by liam — May 28, 2010 @ 11:56 am

  18. […] googled it and I found a great fix for this issue. Here is a link to the fix: https://www.trancefussion.com/blog/?p=101 This entry was posted in Linux Administration, Programming. Bookmark the permalink. ← […]

    Pingback by pdftk error glyphlist.txt loading error: glyphlist.txt on Ubuntu | Amir Saad — September 2, 2010 @ 1:38 pm

  19. Oh my goodness! Awesome article dude! Thank you so much, However I am encountering difficulties with your RSS. I don’t know why I am unable to subscribe to it. Is there anyone else getting identical RSS problems? Anybody who knows the answer will you kindly respond? Thanks!!

    Comment by Carl Keck — July 18, 2012 @ 8:38 pm

RSS feed for comments on this post.

Leave a comment

Powered by WordPress