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.
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.
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.
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.
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).