AirPrint Pi

By popular demand, here’s how to turn your into an redirector.

Note: Recent versions of CUPS (1.5.3, from 2013 onward) already set up the relevant Avahi/Bonjour services, so there’s no need to use airprint-generate. I did, however, have to add the .types and .convs files.

Mind you, this will not be amazingly fast. A with 256MB of RAM (such as the one I’m using for this) will positively groan under the weight of handling large print jobs even if you set it up via raspi-config to leave only 16MB for the GPU.

But it works, and is enough of a matter of general interest for me do document this here (likely someone else has done it already, but I’m kind of ).

Prequisites

The following instructions assume you know how to set up your printer in CUPS, and that you’re OK with administering it remotely from a browser. If you don’t, I suggest reading up on it (there are plenty of tutorials on that out there).

My printer is an , so I’m going to include some HP drivers into the initial invocation. You may want to hunt around for Linux-specific instructions for yours.

I’m also going to add the virtual “printer” because it’s something that I find quite handy indeed1, and a library that airprint-generate needs to talk to CUPS.

Commands

The whole thing, with comments, is this big (assuming you’re running Raspbian) – you can simply paste the lot into bash and get it over with in a few minutes.

# required packages (PDF printer, HP drivers at the end)
sudo apt-get install cups avahi-daemon python-cups cups-pdf hpijs-ppds
# this makes the pi user a CUPS admin
sudo usermod -a -G lpadmin pi
# this enables the web interface
sudo cupsctl --remote-admin
# now set up your printer(s) via the web interface at 
# http://hostname:631 (it will change to HTTPS when required)
# * make sure you print a test page from CUPS! *
# ...and then get the airprint-generate script
wget https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py
# set the MIME types
sudo sh -c "echo 'image/urf urf string(0,UNIRAST<00>)' > /usr/share/cups/mime/airprint.types"
sudo sh -c "echo 'image/urf application/pdf 100 pdftoraster' > /usr/share/cups/mime/airprint.convs"
sudo service cups restart
# generate the service files -- you need to do this again if you add/remove printers
python airprint-generate.py
sudo cp *.service /etc/avahi/services
# and you're done
sudo service avahi-daemon restart

Your printer(s) should show up instantly. Your mileage may, of course, vary, especially when trying to print large documents via a 256MB – and depending on the kind of printer you have, this may turn out to be a nightmare to get working right.

But given that I usually print single pages (4 at most) from my devices and that HP’s drivers mostly work, I expect it to be a fairly long-lasting solution for me.

Not-so-subtle hint: Here’s my . Merry Xmas!


  1. I have it set up with a custom script to mail things I print to it to my account, since web clipping from works rather poorly for my taste. ↩︎

This page is referenced in: