ALL of the following commands will be run as root. If you are not root already, you can become root by entering “sudo su” as user pi.
aptitude install avahi-daemon cups cups-pdf python-cups
- This will update your package list, and install the packages we need
- avahi-daemon is a free zeroconf implementation (open source Bonjour replacement)
- CUPS = Common Unix Printing System – manages the printers for you
This command will take a while, especially after [ ok ] Starting Common Unix Printing System: cupsd. Please be patient here.
Comment out the line just below “# Only listen for connections from the local machine.” with an #, and add some new lines, like this:
# Only listen for connections from the local machine.
#CHANGED TO LISTEN TO LOCAL LAN
# Restrict access to the server...
# Restrict access to the admin pages...
# Restrict access to configuration files...
Require user @SYSTEM
Leave the other lines as they are.
- This will allow access to the CUPS web interface from other machines than your Raspberry Pi itself (on the local network)
- We advise you to change the default “raspberry” password for the user “pi” just in case …
- You can change the port from 631 to something else, but be sure to replace it in the instructions below!
Restart the CUPS service
- This will restart the CUPS service and reload it’s configuration files
Add the user pi to the lpadmin group
This is necessary to allow you to administrate the printers through the web interface as user pi, later on:
AirPrint will have to be enabled after you have added the printers.
CUPS actually has a very nice web-interface. It apparently has been purchased by Apple in 2007, and is being supported by that huge company and the original developer, Michael Sweet. Maybe that is one reason why it really works quite effortlessly. But, let’s begin:
Open your favorite browser, and enter “https://” + your Raspberry Pi’s IP address + “:” + the port (631 as default).
For example: https://192.168.1.11:631/
Your browser will most definitely warn you about a security certificate problem. Please ignore it, and continue (or do you sign certificates for your local machines?)
Hint: CUPS will show up to you in the language your browser indicates to it. Even the directive “DefaultLanguage en” in the configuration file will NOT change that. In other words, to change the language of the CUPS web interface, change your browser default language setting.
Modify CUPS Settings
Click on the Administration Tab, and check “Share printers connected to this system”. Click on “Change Settings”.
At this point you will probably be asked to enter your credentials. If you have added the user pi to the printer management group lpadmin, as per instructions above, you can enter it’s credentials now:
The CUPS server is being restarted.
Connect Printer to CUPS
You can add network printers, or USB printers to CUPS.
Before continuing with the instructions, please ensure that your printer is connected to the network or via USB to the Raspberry Pi , and powered on. You do not need to restart your Raspberry – you can simply plug in your printer right now.
Add a new printer to CUPS
If you have a USB printer, click on “Find New Printers” on the Administration tab (this is called “Verfügbare Drucker auflisten” in German)
CUPS will take a while – and it should list all printers which it has recognized.
Simply add the printer, in this example my trusty Kyocera FS-3900DN (I will only buy Kyocera Laser printers from now on ). My DYMO LabelWriter 450 was also recognized “out-of-the-box”.
Now simply follow the dialogues and enter sensible values:
(Note: the connection line in the screenshot will say something like “usb://…” for USB printers).
Select your Make and your Model here. A lot of printers are listed. If you don’t find yours, try to find a PPD file for it on the web: A PPD File is a “PostScript Printer Description”” File – it describes fonts, paper sizes, resolutions and other capabilites that are standard for a particular Postscript printer.
Now you will be presented with a dialogue which will have different default options to set up, according to your printer.
Here’s the one for the Kyocera FS-3900DN, for example:
Please note: these are default options. If, for instance, the paper sizes your printer supports are not listed here (as is the case for my DYMO LabelWriter 450), simply select the next “matching” one, and set it up under Windows / your Mac correctly.
Now your printer is set up, and you can continue:
Print test page
The CUPS menu “Printers” will list the available printers. By clicking on a particular printer, you can administrate it. For instance, you can print a test page from the Maintenance drop down menu:
CUPS will show you the progress of the print job.
Adding network printers to CUPS
If you have a network printer, we recommend to use the “Add Printer” button instead, and setting up the printer manually.
The CUPS manual recommends to use “HP JetDirect” as it is the most reliable protocol. This works with my Kyocera FS-3900DN.
In the next screen, enter your printer’s IP address, followed by the port (i.e. socket://192.168.1.21:9100 ). There are options to set up secure (encrypted) printing, but this is beyond the scope of this article.
Now you can continue as described above.
Set up AirPrint
In GitHub, there is a script which creates the AirPrint service. In the German article this one translates and elaborates, it is recommended to put it into /opt/AirPrint.
As user root (sudo su):
wget -O airprint-generate.py --no-check-certificate https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py
chmod +x airprint-generate.py
./airprint-generate.py -d /etc/avahi/services
service cups restart
service avahi-daemon restart
- Create a new directory “/opt/AirPrint”, change into it
- Download the airprint-generate.py script
- make it executable
- execute it, and modify the configuration files in the directory /etc/avahi/services (add an XML description of the new printer service)
- restart the CUPS and avahi services
If the ./airprint-generate.py command yields an error, like “image/urf is not in mime types, [PRINTER_NAME] may not be available on ios6 (see https://github.com/tjfontaine/airprint-generate/issues/5)”, please refer to the solution in the German article (there is always Google Translate)
The printers should be available now.
Install printer on Windows
Open “Devices and Printers”. Click “Add a printer”. Select “Add a network, wireless or Bluetooth printer”.
Select “The printer that I want isn’t listed”
Select “Select a shared printer by name”, and enter http:// + Raspberry Pi IP + :631 + /printers/ + your printer’s name (called “Queue Name” in CUPS).
For example: http://192.168.1.11:631/printers/kyo-3900
Again, this could probably be changed for encryption – but is outside the scope of this beginner’s article.
Click “Next”, and continue to install the driver. If you can’t select it from the list, try Windows Update (be patient). If that does not work, try to locate the driver on the vendor’s homepage. I had to do the latter for the DYMO LabelWriter 450.
Remember to set up sensible default settings for your new network printer. These settings will override the settings you set on CUPS – thus you CAN actually print to page formats CUPS does not know yet.
Add printer to Apple Mac
This Apple KB article should help you to set up your printer on your Mac. Unfortunately there’s no Mac here, when we have access to one, we will test it.
Can’t find a network printer
Try to add it manually, by using it’s IP address and the information we have given you in this article. If it still does not work, try changing your printer LAN server settings.
Well, what about SAMBA?
CUPS printers can be shared through SAMBA. This is additional configuration overhead, but may add the possibility for Windows machines to automatically download drivers from the Raspberry Pi. This is beyond the scope of this article.