As a $35 pc with very low power requirements, the Raspberry Pi is uniquely suited to serve many different purposes especially as an always-on low power server. When I first heard of the Pi, I was excited because I wanted it to become an AirPrint Server. This allows Apple’s iOS line of devices to print to the Raspberry Pi which then turns around and prints to your regular printer via CUPS. I used my network laser printer for this, but there is no reason why you couldn’t use a hardwired printer (over USB) on the Pi itself. About a month ago, I succeeded. Last week, I put up a video demonstrating it, and today, I bring you the long-promised tutorial so that you can set it up yourself.
I’d like to thank Ryan Finnie for his research into setting up AirPrint on Linux and TJFontaine for his AirPrint Generation Python Script.
For the purpose of this tutorial, I used PuTTY to remotely SSH into my Raspberry Pi from my Windows 7 running Desktop PC.
To begin, let’s login to the pi which uses the username
pi and password
We now have to install a whole bunch of packages including CUPS and Avahi. Before we do this, we should update the package repositories as well as update all packages on the Raspberry Pi. To update the repositories, we type in the command
sudo apt-get update.
Naturally, this doesn’t quite work as expected, ending with an error requesting another package update. If you get this error just type in
sudo apt-get update again.
It seems the second time is the charm!
Now we need to upgrade the packages installed on the Pi using the new repository information we’ve just downloaded. To do this, we type in
sudo apt-get upgrade.
This will generate a list of packages to install and will then request approval before continuing. Just type in
y and press enter to let it continue.
This will take a few minutes as it downloads and installs many packages. Eventually you will be returned back to a bash prompt.
At this point, we have to begin to install all of the programs that the AirPrint functionality will rely on: namely CUPS to process print jobs and the Avahi Daemon to handle the AirPrint announcement. Run
sudo apt-get install avahi-daemon avahi-discover libnss-mdns cups cups-pdf gutenprint pycups avahi python2 to begin this install.
Looks like some of those have been deprecated or had their names changed. We’ll have to install those ones again in a minute.
For some strange reason CUPS didn’t get installed, even though it was the list of programs to install in the last command. Run
sudo apt-get install cups to fix this.
Once again, it will need confirmation before continuing. As before, just type in
y and press enter to continue.
Once it finishes, you will again be returned to the bash prompt.
Time to install python-cups which allows python programs to print to the CUPS server. Run
sudo apt-get install python-cups to install.
Once you’ve returned to the bash prompt, run
sudo apt-get install avahi-daemon to install the avahi daemon (an mDNS server needed for AirPrint support).
For security purposes, the CUPS server requires configuration changes (managing printers, etc) to come from an authorized user. By default, it only considers users authorized if they are members of the
lpadmin group. To continue with the tutorial, we will have to add our user (in this case
pi) to the
lpadmin group. We do this with the following command:
sudo usermod -aG lpadmin pi (replace pi with your username).
Before continuing, lets start the cups service and make sure the default configuration is working:
sudo /etc/init.d/cups start.
Since we just tested CUPS’s default configuration, we might as well do the same to the Avahi-Daemon:
sudo /etc/init.d/avahi-daemon start.
If you get any errors during the previous two startup phases, it is likely that you didn’t install something properly. In that case, I recommend that you go through the steps from the beginning again and make sure that everything is okay! If you proceed through without any errors then it’s time to edit the CUPS config file to allow us to remotely administer it (and print to it without a user account on the local network – needed for AirPrint). Enter in
sudo nano /etc/cups/cupsd.conf.
The configuration file will load in the nano editor. It will look like this.
Use the down arrow until you come to the line that says
This tells CUPS to only listen to connections from the local machine. As we need to use it as a network print server, we need to comment that line out with a hashtag(
#). As we want to listen to all connections on Port 631, we need to add the line
Port 631 immediately after the line we commented out.
We also need to tell CUPS to alias itself to any hostname as AirPrint communicates with CUPS with a different hostname than the machine-defined one. To do this we need to add the directive
ServerAlias * before the first
<Location /> block.
To continue setting up remote administration, there are several places that we need to enter the line
Allow @Local after the line
Order allow, deny – however this does not apply to all instances of that line.
We now need to save the CUPS config file and exit the nano text editor. To do this hold down
ctrl and press
x. You will be prompted to save the changes. Make sure to type
y when it prompts you.
It will then ask you to confirm the file name to save to. Just press
enter when it prompts you.
Next, we need to restart CUPS to have the currently running version use the new settings. Run
sudo /etc/init.d/cups restart to restart the server.
It’s time to find out the Pi’s IP address to continue setting up printing via the web configuration tool. In my case, my Pi is assigned a static address by my DHCP server of
192.168.1.75. To find out your Pi’s IP address, just run
Once we have the IP address, we can open a browser to the CUPS configuration page located at
ip_address:631. More than likely you will see a security error as the Raspberry Pi is using a self-made SSL certificate (unless you have bought and installed one).
To continue on, click on Proceed anyway or your browser’s equivalent if you are sure you have entered in the correct IP address. You will then see this screen.
From there, go ahead and click the Administration tab at the top of the page. You will need to check the box that says
Share Printers connected to this system and then click the
Change Settings button.
CUPS will request password authentication, and since we added the user
pi to the
lpadmin group earlier, we can login with the username
pi and password
The CUPS server will write those changes to it’s configuration file and then reboot.
At this point, it is time to setup your printer with CUPS. In my case, I am using a Brother HL-2170w network laser printer and my screenshots will be tailored to that printer. Most other printers that are CUPS compatible (check http://www.openprinting.org/printers for compatibility) will operate the same way. If you are using a USB printer, now is the time to plug it in. Give it about a few seconds to get recognized by the Pi and then click the
Add Printer button to begin!
CUPS will begin looking for printers. Just wait till it comes to a list of discovered printers.
Eventually you will come to a page that looks like this:
Once you have chosen the correct printer and clicked continue – you will be brought to the settings page. Make sure to check the box regarding sharing or AirPrint may not work correctly.
You will then have to select the driver for your printer. In most cases, CUPS will have the driver already and all you need to do is select it – but with newer printers, you will need to get a ppd file from the OpenPrinting database and use that.
Then you need to set the default settings for the printer, including paper size and type. Make sure those match your printer so that everything prints out properly.
Once you are done, you should see the Printer Status page. In the Maintenance box, select Print Test Page and make sure that it prints out and looks okay.
If you get a proper test page, then you’ve successfully setup your CUPS server to print to your printer(s). All that’s left is setting up the AirPrint announcement via the Avahi Daemon. Thankfully, we no longer have to do this manually, as TJFontaine has created a python script that automatically talks to CUPS and sets it up for us! It’s time to go back to the Raspberry Pi terminal and create a new directory. Run
sudo mkdir /opt/airprint to create the directory
We next need to move to that directory with the command
Now we need to download the script with the following command:
sudo wget -O airprint-generate.py --no-check-certificate https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py
Next, we need to change the script’s permissions so that we can execute it with the command
sudo chmod 755 airprint-generate.py.
It’s time to finally run the script and generate the Avahi service file(s). Use the command:
sudo ./airprint-generate.py -d /etc/avahi/services to directly place the generated files where Avahi wants them.
At this point everything should be working, but just to make sure, I like to do a full system reboot with the command sudo reboot. Once the system comes back up, your new AirPrint Server should be ready!
To print from iOS, simply go to any application that supports printing (like Mail or Safari) and click the print button.
Once you select your printer, and it queries it and will send the printjob! It may take a couple minutes to come out at the printer but hey, your iOS device is printing to your regular old printer through a Raspberry Pi! That’s pretty cool and functional right? And the absolute best part, since the Raspberry Pi uses such little power (I’ve heard it’s less than 10 watts), it is very cheap to keep running 24/7 to provide printing services!
UPDATE: If you are running iOS6, due to slight changes in the AirPrint definition, you will have to follow the instructions here, to make it work. Thanks to Marco for sharing them!
Followed these instructions and my HP Laserjet m1132mfp airprints over wifi from an iphone. Now I'm trying to airprint directly from ipad to printer using WIFI Direct standard, so that I dont need a router in between. Has anyone tried that.
I've never tried anything with WiFi direct printing. I'd assume that you would need support with iOS (which I believe exists), the printer and the Airprint protocol. I don't know enough about the protocol to indicate whether it would work or not. I've also heard nothing from anyone else regarding this.
Everything works but I have about a 5 to 10 minute lag time to print anything. …SO, it is impressive but also that kind of sucks!?
I have my B model Pi set to only 16mb for the GPU, on the 'modest' overclock setting and a wired Ethernet connection. My printer is a Canon PIXMA MX870 printer connected via wireless-N. I used the built-in gutenprint/cups driver. The only issue I had with the printer was that it wasn't detected until I used its web config page to turn on LPR service notification.
Any ideas for speeding things up a bit?
Unfortunately not, I believe it to be related to how CUPS handles AirPrint jobs but could be totally wrong on that.
Worked fine on my Ubuntu server (rather than a Pi) and a Netgear DP-G310 USB-Ethernet printserver.
Printing seems to take a few minutes to shuffle through the various print queues, but eventually it comes out the printer with no problems.
Glad to hear it. I'm not sure what's causing the delay – but I see it though. I believe it's something to do with how CUPS handles AirPrint requests but no idea on the specifics.
I can’t get it to work. I followed all these steps, but the iPad can’t find it.
My printer is an HP Deskjet 6122 Series, a real old one, connected to the Pi with a USB to 36-pin Centronics adapter.
The printer is shared as Raw Printer over the network, and works like a charm. The response time is very fast, since the conversion of files to printer-input format is done by the drivers on the local systems, and the raw data is passed trough the Pi.
I run my own Linux kernel on the Pi to allow printing with a parallel port, since the default kernel doesn’t come with the usblp kernel module, necessary for the usb to parallel port adapter.
I added a non-raw HPcups copy of the same printer to my CUPS. This one will be slow, but doesn’t need HP drivers that the iPad doesn’t have.
Both CUPS printers work fine on the local network, but neither is detected by the iPad.
The iPad runs iOS 7, and I did follow the iOS 6 fix instructions.
Any idea what may be going wrong?
Can you add Google Cloud Print + iCloud or would that be in some kind of conflict, I've seen tutorials for both separately but not all together?
You should be able to setup both of them together, I've done it before but do not have instructions for it.
I have a link on http://blog.wenzlaff.de/?p=2373
Hearty congratulations! – this is brilliant! and very well documented.
I have it working perfectly under IOS 6.1.3 ipad 2. I implemented it today 3rd Jan 2014. This is the best solution to the tedious Apple incompatibilities that I have come across. Well done.
I have a USB printer plugged into the Pi and it's as happy as anything.
I even got some samba printing working at the same time. (http://mardou.dyndns.org/Privat/raspberry.nsf/id/JUND-95VRCY) , so my printing life is sweet.
Glad to hear it!
Glad to hear it!
excelent guide!! it works perfect for me, with iOS7 and lexmark printers.
I have setup some raspi in the company so my colleagues can print from the ipad.
Very nice post – thanks much
How would i use this with google cloud print? Thanks for your help
I'm sharp this exceptional methodology. I simply uncovered your site with the end goal of from the get go risk also had turned into a freakout. Have post for the reason that I am going to peruse through it again general.
For more quality products visit http://www.ariesdesignn.net
Hey fantastic instructions i actually understood what i was doing
i fallowed your instructions and it works beautifully when its plugged into a wired connection
now i have a edimax usb dongle and i have hooked it up to my wifi and the air print will work just fine for the first 5 minuts of being unpluged and then my phone cannot find it after that time.
is there a wifi time out system in place or do you know of a way to fix this?
I don't know of any timeouts with the Wi-Fi dongle. It should behave exactly the same on Wi-Fi as it would on ethernet. The only thing I would check is the power supply; it may not have the necessary amperage to maintain power to the Wi-Fi dongle continously.
Comparing any smartphone to a full-frame DSLR is not the point of a great camera in a cell phone. Let me see you carry a Nikon D4 everywhere you go. Does it fit in your pant's pocket? Pro level images are possible using an iPhone, I'd suggest it is the skills of the photographer more than any one camera with whatever specs it has.
actually Pi is a great server. My friend told me about Pi. I very much excited to want it to become an airprint server. I heard it also allows apple’s iOs line of devices to print to Rasberry Pi. Thanks for writing the blog.
you bring up Raspberry pi as AirPrint server. Before reading your blog I don’t know about Raspberry pi. Is it safe for windows 7? Please share in details. Thanks for sharing.
Woow. Nice post.
Upsc Nda Result 2018
Upsc Nda Result