A killer app: PDF Editor

653

Author: Preston St. Pierre

Here’s a common situation in the business world: someone sends you (a
Linux user) a contract to fill out and return. If you’re lucky, it’s
a Microsoft Word document that you can open in OpenOffice.org. Often times it’s a PDF. But how can you edit a PDF in Linux?

To be quite honest, things can get tricky. If the
document was created with proper form fields, you can add text to the
document with the free Adobe Acrobat and print it. However, you can’t
save your changes. Also, this only works in the official Acrobat
program – Xpdf doesn’t support PDF forms. Unfortunately Acrobat Professional ($449) is only available for Windows and Mac so that doesn’t help the loyal Linux user.

Recently, I was that Linux user. After doing some investigation and
following a few tips from others, I found two software solutions.
Although these tools are not the easiest to use, they do fulfill the
goal of filling out PDF forms. In addition: they point towards what I
believe could be a true Linux “killer app”: a robust PDF markup tool.

The Tools

The tools I found are Xfig and flpsed. Xfig is a general image editor, while flpsed is specifically for marking up PDF files. It’s important to note that
neither of these programs can actually edit PDF files. Rather, they
can be used to add new text and graphics on top of the file. This is
generally all you need for filling out typical business forms such as
contracts.

I do have to warn you: flpsed is not a finished
program. The flpsed home page
warns: “flpsed is still alpha software!” Having said that, I did find
it usable, although a bit rough around the edges.

Given flpsed’s unfinished nature, it’s not surprising that it is not
to be found in any of the standard Linux distributions.
Fortunately, it’s fairly easy to build from source. First, install
the fltk (Fast Light Toolkit, a C++ GUI toolkit) development
libraries. I installed version 1.1.5 of fltk and fltk-devel from the
Dag rpm repository.

You will also need X11 and ghostscript installed on your system, but
everyone has those these days. Then, simply untar the flpsed source
and run make to build flpsed. After this completes successfully, copy
the flpsed binary to a convenient location such as /usr/local/bin/.

The Xfig image editing program and comes standard on most
Linux desktop systems, so I won’t cover it in much detail here, other
than to point you to the Xfig home
page
for more information.

Using flpsed

Flpsed only operates on postscript files, so the first thing you have
to do is convert your PDF to postscript. To do this, use the pdf2ps
commmand-line too which comes with ghostscript. This is usually
painless since the PDF markup language is a subset of postscript.
After running pdf2ps on your file, you will find a postscript file
with the same name and .ps extension in the same directory. When you
are done editing the file, you can convert it back to PDF with the
corresponding ps2pdf utility.

Flpsed is a completely graphical application, so run it from your
desktop and use the file menu to open the postscript version of your
PDF. After a bit of churning, flpsed will present you with the first
page of your document in a window. You can now edit it as you want.
Click on any area of the page you wish to add text and type away. You
can use the arrow keys at any time when you have a textbox open on
screen to reposition the text in small increments. This allows you to
line up text accurately.

The flpsed user interface is very primitive. You can only add text to
a page: once you add a text fragment, it remains forever
(although you can make it empty). There’s no way to add other
graphical elements such as circles or boxes. You only get one font: courier, for that “I used a typewriter” look, in 3 sizes.

At least on my system, the font displayed in the flpsed editor did not
match the font my printer used. This made exact positioning of long
strings of text difficult as they tend to run off the page when
printed.

You can press <ctrl-n> at any time while editing to move on to
the next page. Any additions you’ve made to the previous page will
remain. One big annoyance I had with flpsed is that you can only move
to the next page with <ctrl-n> or press <ctrl-p> to skip
to the first page of the document. There is no way to move to the
previous page or jump to an arbitrary page in the document. This
means that if you accidentally skip past the page you want in a long
document, you have to start from the very beginning.

Once you are satisfied with the additions you’ve made to a document,
you can save or print it. The save feature writes the file out with
your changes embedded as additional postscript. This means that your
changes are an integral part of the document and you can pass easily
pass it on to anyone as a PDF file (you have to of course turn the
postscript back in to pdf with pstopdf first).

As I mentioned above, flpsed is most definitely alpha-quality
software. It did crash once when I used it. Also, I would
occasionally see a glitch where the text I added to a particular page
of a document would be printed again on an additional blank page.

Time for Xfig

The Xfig method of editing pdf files is decidedly less elegant than
what I’ve described above. However, it has one big advantage: you can
draw anything you want on top of the original document. I was forced
to use the Xfig method with some forms recently because the form
fields contained default values.

It’s a bit of a stretch to say you use Xfig to edit a postscript
file. What you actually do is load the original file into Xfig as an
image and create an overlay Xfig image on top of that. One major
limitation with this approach is you can only operate on a single page
of a postscript (or converted pdf) file.

I won’t go over the details of using Xfig to add text on top of a
postscript page because this
howto
provides a good description. This method does work to add
text and other graphical elements on top of your pdf. However, keep
these limitations in mind:

  • Xfig operates on only one page at a time.
  • You will need both the Xfig file and the original image if you
    want to print it out (the Xfig file references the original image).
  • This is not a very portable solution because you can’t convert
    back to a pdf. Windows users will be very confused if you give them a
    fig file and the original image.

Putting It All Together

Using the combination of flpsed and Xfig, I was able to edit a number
of different PDF documents. I was then able to either print the
resulting documents with my text included, or email the PDFs to others.
Thus, mission accomplished.

However, as you can see from the many caveats above, this is a
cumbersome process. I sincerely hope that in particular flpsed is
improved and expanded. For example, if it included basic drawing
tools, I would not have had to use Xfig.

With a little bit of work, flpsed could be a “killer app” for Linux.
Imagine the scenario: a Windows user comes to you with a look of panic
on his face: “Help! I’ve got a PDF I have to edit. What can I do?”

“No problem,” you say, as you fire up flpsed and save the day. Score
one for Linux.