Raspberry Pi Print And Scan Server part 2: CUPS and AirPrint Setup

In part 1 of this series I explained how to set up a Raspberry Pi powered scanner that could do tricks like one-button-dropbox-scanning. But the goal was to create a Scan and Print server. So let’s take a look at setting up the Printing part so you can share your printer over the network. On top of that let’s add AirPrint so you can print straight from your iPad.

CUPS

For the print serve part we’ll be using CUPS, the most well-known print server package on Linux. Since we only use our Pi as a Scan and Print server it will run CUPS without any problems.

To install CUPS just log in to your Raspberry Pi and enter sudo apt-get install cups . After that we need to add our login user Pi to the printer group. You can do so with sudo usermod -a -G lpadmin pi . 

The whole idea of a print server is that you want to share your printer over the network. Since network sharing is disabled by default you need to enable it. You also need to enable remote access to the management web console. To do this all in one go you can use the command: sudo cupsctl –share-printers –remote-printers –remote-admin .

You can now add and configure your printer in the web admin console. Open a browser an navigate to https://<ip-of-your-pi>:631/admin/ . You can ignore the warning about the dodgy certificate. It’s not like anyone already hacked your Pi or something.

CUPS web admin console

CUPS web management console running on the Raspberry Pi

In the management console click on Add Printer. You need to log in with your pi account. Pick the right local printer and push Continue. Now give your printer a suitable name and make sure you check the Share Printer option. On the next screen pick the right driver (just go for the recommended one that matches you model) and push Add printer.

After setting the default values CUPS will tell you the printer was added successfully. You can click on the link or wait for 5 seconds to go to the printer overview page (which is something like https://<ip-of-your-pi>:631/printers/Brother_HL-2030_series depending on the name you gave your printer during the setup).

Installing the printer on Windows machines

To install the printer on a Windows machine open the Devices and Printers menu and select Add printer. Click on the “The printer that I want isn’t listed” option and click on the “Select a shared printer by name”. Here you need to enter the address of your printer overview page in plain http (so without the s), http://<ip-of-your-pi>:631/printers/Brother_HL-2030_series . After clicking next and selecting the right printer driver you’re ready to start printing.

AirPrint

We could just stop here and enjoy our newly created print server. But if you own an iPad wouldn’t it be cool if it could print straight to your newly shared network printer? In order to do so you need to install AirPrint on the Raspberry Pi.

Since you’ve already got CUPS running and configured your printer correctly (if you haven’t you should do so before continuing) setting up AirPrint is pretty straightforward. All you need is the Avahi deamon, some extra CUPS packages and the AirPrint generation script created by T J Fontaine.

Let’s start with the extra packages and the deamon. To install these type sudo apt-get install avahi-daemon python-cups cups-pdf. And to download the generation script from GitHub use the command wget https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py .

Apple changed the AirPrint protocol slightly in iOS 6 and to make it work you need two additional config files. To create these use the following two commands:

  • sudo echo ‘image/urf application/pdf 100 pdftoraster’ > /usr/share/cups/mime/airprint.convs
  • sudo echo ‘image/urf urf string(0,UNIRAST<00>)’ > /usr/share/cups/mime/airprint.types

The last step is to generate the AirPrint service file for your printer and restart the Avahi deamon. To do so use these commands:

  • sudo python airprint-generate.py -d /etc/avahi/services/
  • sudo service avahi-daemon restart

Now grab your iDevice and open an app that supports AirPrint (Mail or Safari will do fine). To print click on the share button at the top and choose Print. Your printer should show up and now you’re ready to print from your iPad. If it doesn’t work straight away try rebooting your Raspberry Pi.

AirPrint dialog in iOS 6

AirPrint dialog in iOS 6

Because the Raspberry Pi has limited memory and CPU power printing over AirPrint is pretty slow. For me this isn’t a problem since I’ll only use it to print and address, directions or a to-do list. But if you want to print larger documents you’ll need a fair amount of patience. Also the generate script is printer specific so if you ever add a new printer to your config you need to repeat the last two commands.

This concludes part two of this series and by now you’ve configured your Raspberry Pi as a full scan and print server. In the next parts I’ll be adding more features like controlling your scanner from your smartphone or browser and  a copy function (with its own button of course).

15 thoughts on “Raspberry Pi Print And Scan Server part 2: CUPS and AirPrint Setup

  1. Pingback: Raspberry Pi Print And Scan Server part 1: Scan Straight To Dropbox

  2. I have found that if you uninstall all the unnecessary stuff – X, GDM, etc… you can get it printing quite well, even with processing images for the correct drivers

    • You are talking about AirPrint right? CUPS is working pretty well already but AirPrint isn’t doing that bad either actually.

      Does it really help to uninstall X and GDM? As far as I know it only consumes disk space if you never start X-Windows. On my printserver I’ve never even tried to start X…..

  3. Hmm, I managed to get AirPrint working with a somewhat different strategy:

    I read that AirPrint is nothing more than using Apple’s Bonjour service, which is basically a DNS thingie.

    At home I configured a subdomain specifically for bonjour, configured the printer stuff (there’s a tutorial/doc somewhere on the internets) and it’s available to all devices that speak the language of bonjour. This meant installing a specific bonjour service on my windows machines.

    Works pretty nifty. Not too sure whether your method is easier to setup or not, guess there are more ways to rome :D

  4. Thanks but I receive two error message when I try to run the two commands related to the IOS6 upgrade.

    The first is ‘permission denied’
    The second is unexpected token (
    can you suggest what I need to do, please?

    • Are you sure you ran the first command with sudo? If not you’ll indeed get a Permission Denied error. Otherwise you should be just fine.

      The second one is strange. If you’ve copy/paste the command from this website into your SSH session you might want to check on the ` vs ‘ … typing the single quote signs yourself is probably safest.

      • I had the same Permission Denied problem, and sudo just wouldn’t work. Finally found it would work in a full root shell (sudo su).

  5. So as long as you set this up, can you just leave the Raspberry Pi on the shell without starting X after a reboot?

    • That’s right. There is no need for X since these are all headless services/daemons.

      In fact I don’t think I’ve ever started X on my print/scan server.

  6. I’m getting the Permision denied error on the wget command. The script is downloaded, but throws a “Cannot write to ” error.

    Had already setup CUPS, and it’s running.

    Good article, BTW!

    • Make sure you’re not using sudo with wget and are downloading to a directory that doesn’t require sudo access such as ~/

  7. Fantastic! Worked first time for me. The only issue was fetching the CUPS packages as a few were not pulled down. Ran the installer again and everything worked fine.

Leave a Reply