Printing from the iPad without buying a new printer

Ok, so you’ve got a snazzy new iPad, and would like to print. Since iOS 4.2, Apple has had AirPrint, which only works with a small set of HP printers. While yes, it’s super cool to be able to print from the iPad, how much will you really do this? If it’s enough to warrant buying a new printer, good for you. If you’re like me, and want to have the ability to do so, but probably will rarely do it. Read on to find out more.So, just what is AirPrint? At the core, AirPrint is just a special Multicast DNS (aka Bonjour in Apple parlance) or DNS-SD (DNS Service Discovery) advertisement on your network, and directs devices to use IPP to print to a given device. You don’t need to do both.

So maybe your printer already advertises mDNS on the LAN, as mine does, but doesn’t pass out all the parameters AirPrint devices expect to see. From what I’ve been able to determine from a variety of sources, here’s what I know:

IPP is used for the actual printing

Either mDNS or DNS-SD for advertising the service availability

mDNS for local LAN

DNS-SD for wide-area support

DNS-SD announcement is in _universal._sub._ipp._tcp

AirPrint requires a TXT record called URF

All current AirPrint apps seem to print as PDF, but field opens the door for additional formats – PDF support will be key further down in the process

I opted to create a VM on my existing VMware ESXi server at home. I used the FreeBSd 8.2 x86 (i.e. 32-bit) version. I just did a basic install, then added packages from the CLI later. I installed the packages I needed:

pkg_add -r avahi cups gutenprint-cups py26-cups

This will pull the packages for avahi (mDNS server), cups, the Gutenprint cups drivers and the python interface to cups.

First, you’ll want to configure cups so that everything on your local LAN can print to the cups server. This is covered quite well in the cups docs, so I’ll omit those directions. Next, add your printer to the cups server. Again, this is a very simple process, so I’ll omit that as well. After you get the printer setup on the cups side, print a test page to be sure the communication between your cups instance and the printer is functioning. Got it working? Good.

Next, you’ll run a script from a guy named TJ Fontaine that generates the Avahi service file. So, the script talks to your cups server and pulls the list of available printers, and spits out service files for them. I wasn’t thrilled with the quality of the XML that got shot out by the program – it was almost all on a single line. I took the time to break the lines and indent properly, and for my HP LaserJet 2420dn, I wound up with:

Drop this in /usr/local/etc/avahi/services, and Avahi will start advertising the service. You’re going to need to generate your own service file, but with the script linked above, this is pretty simple.