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

So, what do you need to make this work?

  1. A printer that supports printing via IPP
  2. A server that can run cups & avahi
  3. A suitable printer driver for cups that supports your printer and can handle PDF documents (foomatic, gutenprint, etc. are fine choices)

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:

[airprint:root](04:47 PM)
/root# cat /usr/local/etc/avahi/services/AirPrint-OfficeLaser.service
<?xml version="1.0" standalone='no' ?>
<!DOCTYPE service-group  SYSTEM "avahi-service.dtd">
<name replace-wildcards="yes">AirPrint OfficeLaser @ %h</name>
        <txt-record>note=hp LaserJet 2420</txt-record>
        <txt-record>product=(GPL Ghostscript)</txt-record>

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.

Now, go grab an iPod Touch, iPhone or iPad running iOS 4.2 or later.  Launch Safari, print something.  Your newly created printer should show up as available.  Print there, and whammo, you’re done.

One thought on “Printing from the iPad without buying a new printer”

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s