Turn your Linux box into a PDF-making machine

4519

Author: Joe 'Zonker' Brockmeier

Remember the paperless office? By now we were supposed to be handling all of our documents digitally, and saving trees by using computers to handle everything electronically. If you’d like to make backup copies of ephemeral content without printing it out, turn your Linux box into a PDF generation device for your entire network.

What sort of things might you want to save as PDFs? When you buy stuff online, virtually every site provides a receipt, which you may want later if the order email is lost or if you need to send in a receipt for expense reports. However, you may not want to print all of them out just to keep them around, and Firefox only supports writing to PostScript, rather than PDF.

What you’ll need is a Linux box with the Common UNIX Printing System (CUPS) and the CUPS-PDF driver. I set this up on Ubuntu Feisty, but it should work on any Linux distro with CUPS and the CUPS-PDF driver.

By default, CUPS-PDF is not installed, so grab it by using sudo apt-get install cups-pdf. You should then be able to add a fake printer that will convert print jobs to PDF files. Go to System -> Administration -> Printing to bring up the Printer configuration dialog. Select New Printer from the toolbar, and walk through the New Printer Wizard. You can give the printer pretty much any name you want. PDF seems like a logical choice. The Description and Location fields are optional.

On the next screen, when asked to select a connection, choose Virtual Printer, and leave the device URI as it is: cups-pdf:/. Next, on the screen where you can select a Printer from the database, choose Generic. On the next screen, choose PostScript as the Model and as the driver for the printer. Then you’ll see a screen that says “Going to create a new printer PDF at cups-pdf:/.” Click Apply and you should have a virtual PDF printer.

Now you should be able to create PDF files from most Linux apps by sending your print jobs to the PDF printer. When you send jobs to the printer, they’ll be saved to a directory under your home directory that’s named after the virtual printer — so if you choose PDF as the name of your virtual printer, then the jobs will be sent to /home/yourusername/PDF.

Most Linux apps are fairly well-behaved, but I’ve noticed that some jobs come through as zero-length files even though the applications don’t indicate any problems when printing. For example, Opera happily prints to the virtual printer, but the resulting jobs are empty files. Firefox and Thunderbird print to the virtual printer just fine.

Many GNOME and KDE apps now have the ability to print directly to PDF or export a file to PDF, so it’s not necessary to utilize the virtual printer. However, where the PDF printer comes in really handy is if you have one or more Windows machines on your network and you’d like to generate PDFs from Windows apps without spending the money on Adobe’s tools.

Sharing with Windows

It’s fairly straightforward to set up sharing with Windows. You’ll need to make some simple edits to the CUPS configuration file. On Ubuntu, use sudo vi /etc/cups/cupsd.conf.

First, make sure that you have the port set correctly:

# Allow remote access
Port 631
Listen /var/run/cups/cups.sock
Browsing On
BrowseOrder allow,deny
BrowseAllow @LOCAL
BrowseAddress @LOCAL
DefaultAuthType Basic

Then, under the first Location directive, you’ll want to have something like this:

<Location />
  # Allow remote administration...
  Order allow,deny
  Allow From 127.0.0.1
  Allow From 10.0.0.*
</Location>

The line you want to change is Allow From 10.0.0.*. You’ll want to make sure that the IP address reflects your network.

Next, restart CUPS:

sudo /etc/init.d/cupsys restart

Now you can set up the new printer on Windows. In the Add Printer Wizard in Windows, you’ll select “Connect to a printer on the Internet or on a home office network:” and set the URL as http://ipaddress/printers/PDF. Windows should see the printer. Now it’s time to choose the printer driver. I Googled a bit and found that the consensus seems to be that if you want color PDFs, the HP 1200C/PS driver is the way to go.

Finish walking through the wizard and try to print. If you succeed you will find a PDF waiting for you on your Ubuntu system. By default, if you print to the Linux machine, the PDF files will be saved to /var/spool/cups-pdf/ANONYMOUS. This is in contrast to printing locally, which saves as /home/yourusername/PDF. To change the directory, uncomment this line:

#AnonDirName /var/spool/cups-pdf/ANONYMOUS

and modify it. For example, if you want to print to your home directory under a directory called shared, you could use:

AnonDirName /home/shared

Restart CUPS again and you should be golden.

With any luck, armed with a new PDF “printing” machine, you can make copies of documents you want to save without having to kill a tree in the process.