Living without Windows!

by Jos Visser

Part 13: The Portable Document Format

Go back to the index


For quite some time now I have been a fan of the Adobe Portable Document Format (PDF). It is perhaps the only document format that can be viewed on about any platform in the world, due to the freely available (and therefore ubiquitous) Acrobat Reader. The PDF has been specifically designed for packaging, distributing and reading documents electronically. Apart from the fact that almost everyone can read PDF documents, one of the other advantages it gives us is that it can not (easily) be edited. Therefore, when we distribute course material or white papers electronically, it is not easily possible for naughty copycats to change or remove the author or copyright and pass it on as an original work.

In order to create PDF documents we had acquired the full Adobe Acrobat package some time ago. It contains (amongst others) the PDF Distiller and the PDF Writer. The Distiller turns a PostScript file into a PDF document. The Writer installs itself as a printer driver so you can print directly to PDF files from your favorite publishing or word processing programs. The full Adobe Acrobat is one of the best software packages we ever bought. It contains all the features you need, is easy to use, and when it crashes (as is almost unavoidable in Windows :-) it even crashes with a smile!

Unfortunately, Adobe Acrobat is only available for Windows and for the Macintosh. When moving to Unix on my primary laptop computer, I had to leave Acrobat behind me as well.

One of the first things I subsequently did was sending Adobe an e-mail outlining my situation and asking them whether a port of Acrobat to Linux was to be expected. They never answered that! The next thing I did was surfing to my favorite portal (Yahoo) and entering "PDF Linux" as the search string. One of the first entries that popped up contained a reference to "PStill", a PostScript to PDF convertor for Linux. I downloaded PStill, archived it and decided to take a look at it Real Soon.

I want/need to make a PDF

Soon afterwards, the need to make a PDF popped up. I was sitting behind my laptop at the dining table writing a letter to some one or other. My only printer is however still connected to my desktop computer upstairs, which happens to be running Windows 95 (because otherwise I cannot run Pippi Langkous, Freddi Fish, the Teletubbies or any of the other CD-ROMs I have bought for my daughter Merel). The letter in question was obviously written with Applix Words, of which I only have the Linux version. The obvious route I then was to create a PDF on my laptop, take it upstairs on a floppy, and print the letter from the Acrobat Reader on my desktop. Easier said than done. I still had not looked at PStill and this letter had to get out tonight! Pragmatic as I am, I printed the letter to a PostScript file, took this file upstairs, started the Acrobat Distiller (under Windws 95), converted the PostScript to PDF, viewed the PDF with the Acrobat Reader, and printed it from there.

There had to be something easier than this!

Getting ps2pdf

Some time before, my NLUUG collegue Chel van Gennip had pointed me to Ghostscript's ability to convert PostScript to PDF. I had then looked up the Ghostscript web site to investigate this feature. It seemed that Ghostscript 5.10 onward contains a program called "ps2pdf" which converts a PostScript document into a PDF file. When installing my SuSE Linux system I had installed Ghostscript but I was unaware which version. Fortunately, RPM package names include a version string so I was able to determine the currently installed Ghostscript version through a "rpm -a -q" command and inspecting the output. It turned out I had installed Ghostscript 4.3.

So, I downloaded the then latest Ghostscript (5.50) and started to gather courage to compile and install it. Although not particularly difficult this is something I try to avoid as much as possible, since I would then either have two Ghostscripts on my system, or, if I chose to replace the current Ghostscript with the new one, I would mess up the RPM administration of the system. On a hunch I decided to first start the SuSE system administration/update tool YaST to see if it could be used to download a newer version of Ghostscript from the SuSE web site. To my luck and joy, YaST turned out to have an option called "Update System". When instructed to do so, it contacts the SuSE FTP site, analyses the packages there, compares them to the packages installed on your system and then spits out an upgrade recommendation if the server has newer versions of the packages you have installed. I concluded that the SuSE people update their site regularly with newer versions of packages. Splendid! This is a very handy feature and from this place I want to thank the SuSE people for their effort in providing this function

YaST advised me to update a whole bunch of packages, amongst which Ghostscript. I gave it the "go ahead" and it started downloading stuff and updating packages. I waited, time passed. Needless to say, a fast Internet connection (in my case a cable modem) comes in handy. After the download was completed I first rejoiced in the fact that I had upgraded a major part of the system and did not need to reboot! I then immediately proceeded to run ps2pdf on a stray PostScript file I had lying around. The result was a very acceptable PDF file. Hurrah!

Some small problems

However, technology hardly ever does completely what you want. When I converted another Applix document the end-result looked kind-a terrible. It turned out that I had decided to use the Applix Dutch font (obviously for emotional reasons), which did not convert very well into PDF. Hmmm, However, when I converted the document to the more standard Times Roman it all looked great again. I am no font guru but I can imagine that PDF knows only a limited set of fonts by heart and that others are incorporated or rendered as bit maps. Maybe PStill worked better? I gave some attention to PStill but the results were inconclusive: PStill looked more complete, but also more difficult to configure (ps2pdf requires no configuration at all, but maybe results could be improved with PStill as well.

I am still hoping that Adobe will see the light and bring out their Acrobat suite for Linux. Could somebody help me convince them please?

Printing to PDF

One of the handy things of Acrobat under Windows is that you can immediately print to a PDF file using the PDFWriter: a Windows compatible printer driver which can be used by any application that can print. On a rainy sunday (of which there are quite a few here in the Kingdom of the Netherlands) I decided to extend the Linux printer spooler with a PDF printer driver script which would allow me to do the same. Since Unix is brilliant, printer drivers can be written in scripts (in this case Perl scripts). This is hardly the place to completely describe the solution (it is included as a reference further down this document). Suffice it to say that I wrote a small printer driver that can process PostScript, DVI and text files, turns them into a PDF file, stores that PDF file in the "$HOME/lppdf" directory and mails the name of the generated file to the user who printed the file. It is not perfect, but it suffices (for me). The printer driver uses the "a2ps" program to convert an ASCII text file into a PostScript document so that ps2pdf can process it. Likewise, the "dvips" program is used to convert a TeX DVI file into PostScript.

The "pdf" printer has the following definition in the "/etc/printcap" file:


The "lppdf" printer driver script looks like this:


require "";

# Some initialisation
# ------------------------------------------------------------------------
umask 022;

# See if the the user has a writeable lppdf directory
# ------------------------------------------------------------------------
use User::pwent;

if ($pw=getpwnam($user)) {
        $pdftemp="$lppdfdir/lppdf$$.pdf" if (-d $lppdfdir and -w $lppdfdir);

# Copy stdin to the temporary Postscript file
# ------------------------------------------------------------------------
# I used to have
# system("cat >$lpfile");
# here, but this does not work with a Threading perl because of a bug in the
# Linux thread implementation. Well, then, a simple loop should suffice.
print LPFILE while <STDIN>;

# Check to see whether the file is a TeX DVI file or a text file
# If so, convert it using dvips or a2ps
# ------------------------------------------------------------------------
$_=`file $lpfile`;

if (/^$lpfile: TeX DVI file/) {
        system("/usr/bin/TeX/dvips -o $pstemp $lpfile");
} elsif (/^$lpfile: PostScript document /) {
} else {
        system("/usr/bin/a2ps -1 -nP -p $lpfile >$pstemp");

# Convert the postscript file to PDF
# ------------------------------------------------------------------------
system("/usr/bin/ps2pdf $pstemp $pdftemp");

# Mail the user about where to find the generated PDF file
# ------------------------------------------------------------------------
if ($user)
        chomp $now;
        $ls=`ls -l $pdftemp`;
        chomp $ls;
        print MAILTEMP <<EOF;
Dear $user,

On $now I printed your file to an Adobe Acrobat
Portable Document File. This file can be found in $pdftemp.

The URL is: file://$pdftemp


Yours truly,

Your friendly lppdf lp interface script.
        system("mail -s 'lp generated a PDF' $user <$mailtemp");

As you can see, hardly rocket science, but nice to have! Feel free to copy this script, but remember that all problems you run into are yours to solve!

Last change: 13th march 1999 by me