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.

Powered by WordPress