Printing to a PDF File

There is a handy little utility by the name of cups-pdf that allows you to set up a "Virtual Printer" in CUPS that outputs any file you attempt to print to a PDF file.

cd /usr/ports/print/cups-pdf
make OUTPUT_DIRECTORY=~/cups-pdf install clean

By default, cups-pdf will output PDF files to /var/spool/cups-pdf/xaenn/, where xaenn is your username. This is all well and good, but /var is a pretty small slice of our FreeBSD partition table and we don't want to fill it up. You can change the output directory to whatever you want, but in our example a PDF would be output to /home/xaenn/cups-pdf/xaenn/, where xaenn is the name of the user who started the print job.

Now we need to restart CUPS before we can set up our Virtual PDF Printer.

/usr/local/etc/rc.d/cupsd restart

Follow our instructions here to add a printer to CUPS, but this time choose "Virtual Printer (PDF Printer)" for the Device:

On the following screen, select the "PostScript" driver for Make, and on the screen following that, select "Generic postscript color printer", which should be your only option, for Model. Click "Continue" and you should see a message that your printer has been added successfully. It'll look something like this in your Printers section of CUPS:

When you wish to convert a file to a PDF, simply Print as you normally would, choosing the PDF printer instead of another printer.

This will output a file to /home/xaenn/cups-pdf/xaenn/. As the file will probably have some kind of random name set by the application you printed from, you'll want to change it to something more descriptive. You may also wish to move it to another directory.

Although most PDF files created in this manner will be owned by your user, a Printer Test Page will be output to /home/xaenn/cups-pdf/root/, and will be owned by root. (You won't be able to manipulate it as your user unless you change its ownership). To change the ownership:

chown xaenn test_page.pdf

Where xaenn is your username and test_page.pdf is the file you want to change ownership of.