Aug 272013
 

CUPS_printer

Prerequisites

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.

Install packages

aptitude update
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.

Edit /etc/cups/cupsd.conf

nano /etc/cups/cupsd.conf

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.
#Listen localhost:631
#CHANGED TO LISTEN TO LOCAL LAN
Port 631
# Restrict access to the server...
<Location />
  Order allow,deny
  Allow @Local
</Location>
 
# Restrict access to the admin pages...
<Location /admin>
  Order allow,deny
  Allow @Local
</Location>
 
# Restrict access to configuration files...
<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow @Local
</Location>

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

service cups restart
  • 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:

adduser pi lpadmin

AirPrint will have to be enabled after you have added the printers.

 

Add printer(s)

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/

CUPS Admin interface

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

CUPS-interface-raspberry-pi

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

cups-administration-tab

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:

credentials-required

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-find-new-printers

CUPS will take a while – and it should list all printers which it has recognized.

add-kyocera-fs3900dn-cups

Simply add the printer, in this example my trusty Kyocera FS-3900DN (I will only buy Kyocera Laser printers from now on Winking smile). My DYMO LabelWriter 450 was also recognized “out-of-the-box”.

Now simply follow the dialogues and enter sensible values:

add-printer-step-2-example

 

cups-add-printer-iii

(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:

kyocera-fs-3900dn-cups-default-options

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-test-job

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.

appsocket

The CUPS manual recommends to use “HP JetDirect” as it is the most reliable protocol. This works with my Kyocera FS-3900DN.

cups-socket

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

mkdir /opt/AirPrint
cd /opt/AirPrint
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

This will:

  • 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”.

image

Select “The printer that I want isn’t listed”

image 

image

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.

 

 

Problem solving

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.

References

  • pi3g

    Yes, you can actually use a Raspberry Pi to share your DYMO LabelWriter with all of your local network.

  • Christijan van Steenbeek

    Die Installation und Einrichtung von Cups war tatsächlich super Simpel, mein Laserdrucker printet nun munter auch ohne eine Komplizierte App.

    Vielen Dank für das Testen.

    Schwieriger habe ich mich bei der Einrichtung des WLAN-AP getan,
    hier etwas übersehen, da etwas überlesen,
    in der einen Konfigurationsdatei Leerzeichen drin die hostapd killen, …

    Nach nun knapp drei Stunden funktioniert es nun endlich (zumindest als einfacher Accesspoint – die Fallback-Option über einen zweiten Stick habe ich noch ncht getestet wegen “TP-Link v2” und zu wenig Zeit die Treiber auch noch zu Installieren)

    • pi3g

      Danke fürs Feedback. Die TP-Link v2 Treiber sind als Package in Entwicklung bei uns, allerdings hat der Programmierer gerade leider Urlaub … ich halte Sie auf dem Laufenden.

      • Christijan van Steenbeek

        Hätte übrigens noch Ingeresse an einm zweiten Pi,
        – Pi B
        – Cooling Kit
        – Netzteil 2A
        – WLAN Nano Adapter
        – Gehäuse LibreOffice
        (oder als Idee: eine “XBMC”- Mediacenter – Sonderedition)

        Zu welchm Preis wäre das Paket anbietbar?

        • pi3g

          Bitte kontaktieren Sie mich über http://www.pi3g.com/kontakt für die Preisauskunft (im Prinzip ein abgespecktes LibreOffice “Fun” Kit) – ich mache Ihnen ein Sonderangebot. Bitte beachten Sie, dass in jedem LibreOffice Kit eine Spende an die Document Foundation enthalten ist!

          Wir bieten ja bereits ein XBMC-Derivat basierendes Movie Kit an – mit Raspbmc vorinstalliert. Das besondere an dem Gehäuse ist die transparent rote Farbe. Sie können es über unseren Shop bestellen:

          http://shop.pi3g.com/pi3g_de/pi3g-kits/pi3g-movie-kit.html

  • Pingback: บันทึกการใช้ Raspberry Pi ตัวที่ 1 : Print server | Aekseed()

  • Daniel Lahmann

    Ich habe alles wie beschrieben eingerichtet. Das Drucken der Testseite direkt über CUPS funktioniert ebenso wie das Einbinden des Druckers in WIndiws und das Drucken der Windows-Testseite. Nur leider wird der Drucker von keinem unserer insgesamt vier ios-Geräte über AirPrint erkannt. Die MeinDrucker.service Datei wurde durch das Phyton-Script ohne Murren generiert und befindet sich im etc/avahi/services-Verzeichnis. Neugestartet wurden sowohl der cups- als auch der avahi-service nach dem Erstellen.

    Was könnten denn mögliche Fehlerquellen sein?

  • Pingback: How To: Using Your Raspberry Pi as a CUPS Print Server - The Linux Cauldron()

  • Nandan

    Thanks, this was useful!

  • Tobias Moser

    Ich habe einen normalen billigen Epson Drucker SX 218, der ist kein Netzwerkdrucker, funktioniert der dann trotzdem wenn ich den über den Raspberry Pi den ich mit Samba als Medienserver (NAS) einrichten möchte, oder braucht man generell einen netzwerkfähigen Drucker?

    • Tobias,

      wenn der Drucker per USB angeschlossen werden kann und von Linux (bzw. CUPS) unterstützt wird, dann kann man auf den Drucker (über CUPS) per Netzwerk drucken.
      Ich hatte selber den DYMO Label Writer 450, der nicht netzwerkfähig ist, so netzwerkfähig gemacht.

      Max

  • Rock “Rock” Robbins

    Super Helpful. Finally able to print to my local printer with regular windows programs.

    My URL for my printer on my Raspberry PI 3 was…
    http://192.168.0.13:631/printers/HP_Laserjet_1200

    So, local IP on port 631, and the “printers” plus my printer name which you can see in the CUPS admin screen for the printer.

    It took quite a while for Windows to add it, but it worked, and now I can print outside of Chrome – which is just what I needed.

    Thanks!

Optimization WordPress Plugins & Solutions by W3 EDGE