Apple Airprint is a technology (a zeroconf implementation under the bonnet) which allows apple devices to detect, configure and print without any overt configuration on the part of the user.

The bad news is that in only works for a handful of airprint printers natively. But never fear, Linux to the rescue!

At this point I’m going to assume that you have a Linux box somewhere on your network acting as a file and print server (pretty regular kit in most geek homes).

Set up your printer

The first step is to set up CUPS on your linux server and then installing the appropriate printer driver for your printer.

I won’t go into detail here as there are numerous guides out there on the wider web, but mostly this is a matter of installing cups and foomatic and then visiting the cups configuration website on the server (localhost:631 usually) and adding your printer.

Make sure that the printer is shared. Print a test page.

One gotcha I found is that my default configuration only allowed connections from the local machine, even though the printer was marked as shared (although frankly I was cheating since most of my computers printed to my server over a Samba relay, but that’s by the by).

Take a look at /etc/cups/cupsd.conf and make sure that has an Allow From from your local network. E.g.


<Location />
Order Deny,Allow
Deny From All
Allow From 127.0.0.1
Allow From 192.168.0.0/24
</Location>

Export the printer

The next step is to install the zeroconf demon, which is called Avahi. This varies from system to system, but on debian this is pretty much a matter of apt-getting avahi-daemon. You may also want avahi-discover so you can browse the exported devices on your network.

Assuming you’ve correctly set up and shared your printers in CUPS the next step is to generate an avahi configuration for it. Thankfully, there’s a handy Python script called airprint-generate, available on github which does much of the donkey work.

Copy the resultant file to /etc/avahi/services and restart the avahi demon.

If your printer is password protected, you will want to add a <txt-record>air=username,password</txt-record> field to the file before doing so. Where username and password is the literal cleartext strings sent.

Profit!!!

Theoretically that should be it. After the configuration, and restarting the various demons involved your printer should be available to the various iOS devices kicking around your network.

Let me know if you have any questions!

Update for IOS6 users

If you are using IOS6 and are seeing a “no airprint printers found” when you try and print (even when ios5 devices can print fine), you must make a small configuration change to CUPS.

Create two extra files in /usr/share/cups/mime:

airprint.types

image/urf urf string(0,UNIRAST<00>)

airprint.convs

image/urf application/pdf 100 pdftoraster

Then restart CUPS before regenerating the avahi configuration file for your printer using airprint-generate as documented in the steps above. Replace your existing avahi printer configuration with this new one and restart avahi.

You printer should now be visible again to both ios5 and ios6 devices via airprint.

15 thoughts on “Howto: Printing to any printer with an iPad/iPhone and Apple Airprint

  1. A few items for people who are following these instructions:
    1. I had to point a browser to http://localhost:631
    2. Under server settings, I checked “Share printers connected to this System”.
    3. I also modified the existing printer to make sure sharing was enabled (fedora’s printer config was lacking).
    4. I don’t know if #2 would have done it by itself without doing #3. Now it works! Profit!

  2. Ubuntu 10.LTS linux 2.6.35 backport delivers the printer name to iOS7 but no job appears in /var/spool/cups … found that pdftoraster was in /usr/share so I’ve copied it to /etc/cups.. still trying

  3. Great stuff.
    Debian wheezy CUPS package already contained the Avahi package (and foomatic) and even without configuring the avahi part the iPad here prints now.

    I haven’t looked into CUPS for some years and was surprised to see the progress there with the easy printer ppd selection and my printer already being predeteced. Where is the fun in that …

    Thanks

  4. 3 Feb 2015,

    Your description provided some details I didn’t see on either the programmer’s GitHub site on the Linux magazine article about this. They involved simple but important items like regenerating the python Airprint file after restarting CUPS and following this with restarting avahi.

    I was dubious it was going to work with my wife’s iPad, because it is up to iOS 8 and it seems with upgrades/updates of the iOS, many outside things get broken.

    A valuable and appreciated post.

  5. I could not get this working on ubunut 14.04 through ios7. I can see the printer on the my iphone but unable to print. Trying upgrade on cups!

  6. Yes. Got it working. Though the printer was shared on the settings, it was not actually shared. I had to visit http://localhost:631/admin and then enable “Share printers connected to this system”. Now it is all good. Thanks a ton for the steps 🙂

  7. Done on Jan 3, 2016



    To access the printer via an iOS device such as an iPad, see these:
    http://www.linux-magazine.com/Online/Features/AirPrint
    https://www.marcus-povey.co.uk/2011/11/11/howto-printing-to-any-printer-with-an-ipadiphone-and-apple-airprint/
    To manage the printers, go to https://192.168.0.12:631.
    Also, I set up my server using a static address. It’s ever-so-slightly possible this has created some problems for me with accessing the router admin. This might be solved by reverting to a DHCP address in the samba configuration.

  8. So I’ve got a Pi, a few Apple devices and a Brother network-enabled laser printer, so I thought: “Hey, wouldn’t it be wonderful if I could print directly from the iDevice to the printer?”
    It really would, but Brother’s app requires that you (re-)open whatever needs printing in their built-in browser, so that’s a few extra steps than I am happy with for printing from Safari, etc. (NOTE: The network scanning function from the app is pretty amazing, however)
    The workaround: Use the PI as an AirPrint server (since it’s already handling other ‘always-on’ functions) – easy peasy! I’ve seen Brother’s got a Linux driver on their website!
    UPDATE: Something got borked, so I did some debugging; turns out the ‘share printers’ option needs to be set in CUPS (see Step1’s update), and with the MIME types configured (maybe? Added step5), CUPS support Airprint directly (iOS 6+), without avahi??
    Step 1: Install/setup CUPS
    Easy enough, I followed these steps, which basically amount to:
    Install CUPS: sudo apt-get install cups
    Allow your user admin rights (to configure cups): sudo usermod -a -G lpadmin pi
    I skipped some of the more questionably secure mods in the CPUS config-file, namely:
    allowing printing via (CUPS server) to any machine on the LAN (since my printer is already network-enabled & I only need to add AirPrint support), and
    opening up the admin interface to any machine on the LAN (since I have a monitor on my pi and am comfortable working with X11-redirects)

    Restart CUPS: sudo /etc/init.d/cups restart
    Add a printer via the admin WebUI (http://localhost:631)
    Click on the ‘Administration’ tab, then on ‘Add a Printer’

    http://www.howtogeek.com/169679/how-to-add-a-printer-to-your-raspberry-pi-or-other-linux-computer/

    UPDATE: You MUST check the ‘Share printers connected  to this system’ option, even though this seems less secure – see the UPDATE below for more on security.
    GREAT! My printer is detected by CUPS! …Oh wait, my model isn’t listed😦

    UPDATE: For the security-minded, I came across this little gem by Marcus Povey: Limit printer access to your local LAN and loopback via /etc/cupsd.conf:
    <Location />  Order Deny,Allow  Deny From All  Allow From 127.0.0.1  Allow From 192.168.0.0/24</Location>
    Don’t forget! You need to specify the NETWORK address, not the address of a specific host, or it will get stuck! (Thanks lifeafter2am!)

    Stuff I tried, but ultimately gave up on:
    Remember that wonderful Linux driver on Brothers’ website? Download and install the .deb package… Oh wait, it’s an x86 driver😥
    Finding a .ppd in the cupswrapper and LPR .deb packages (ar vx <filename>.deb to open them, in case you were wondering)
    Then, the jackpot. A fine gentleman named Peter De Wachter was kind enough to build a brother driver with which CUPS can print to a few models of DCP- laser printers – INCLUDING MINE! The source code is graciously shared on GitHub under a GPLv2: https://github.com/pdewacht/brlaser
    If you run into similar issues (missing linux armhf driver support from the manufacturer), you can try finding a suitable printer driver here: http://www.openprinting.org/printers
    Step 2: Installing the brlaser driver
    Special thanks to ‘hal58’ who wrote the ‘Jackpot’ post referenced above about getting his brother printer working with his Pi: https://www.raspberrypi.org/forums/viewtopic.php?t=116509&p=898138
    His instructions amount to:
    Download the source code .zip from https://github.com/pdewacht/brlaser
    Install CUPS and software libraries/compilers:  sudo apt-get install cups build-essential libcups2-dev libcupsimage2-dev automake
    I had an issue with ‘automake’, and hal58’s ‘automake-1.11’. An ‘apt-get update’ cleared it up.

    Prepare, configure, build and install the driver: ./autogen.sh; ./configure; make; sudo make install
    Restart CUPS service: sudo service cups restart
    Hooray! Now back to the original guide!
    Step 3: Finish adding the printer
    Getting back to the interrupted ‘Add Printer’ process in CUPS WebUI, under the ‘Model:’ field just select the line ending with “using brlaser v3 (en)”
    That’s it! 1hr later, I can print!! – Who says Linux/RPi aren’t fun?😉
     Step 4: Install  avahi-daemon
    UPDATE: This step (avahi-daemon) may not even be necessary!?
    While debugging (after finding out my CUPS was not set to share printers), I had visible AirPrint printers in my iPhone: “AirPrint-Brother” (from /etc/avahi/services/airprint.service) and “Brother DCP-XXXX” (directly from CUPS??)

    Most of the guides tell you to simply sudo apt-get install avahi-daemon, but somehow omit a key step: avahi’s .service config-file! (SERIOUSLY!?)
    Step 4a: setting up the AirPrint service (avahi-daemon)
    The ones that do seem to be aware that avahi is not simply plug-and-play, refer to a python script that will auto-create and configure the .service file required.
    Disclaimer: My malfunction is that I don’t like running a random script called “airprint-generate.py” from github and hoping for the best… call me paranoid. Part of the problem is that I don’t know enough python to (time-effectively) audit that the script is actually doing what it’s advertised to do, and nothing more.
    Fortunately, good ol’ google led me to archlinux, who gave a sample config-file and listed what should be customised: https://wiki.archlinux.org/index.php/avahi#Airprint_from_Mobile_Devices. As far as I can tell:
    adminurl is the same link as you would use to administrate your printer via CUPS’ webUI (Administration > Manage Printers > ‘PrinterName’),
    rpand ty are sub-strings of adminurl, and
    as for nameand note, just pick a printer name and location-hint that make sense (will be displayed in the iOS device looking for printers)
    Copy-paste the sample from ArchLinux into a text file and update the fields above before saving, e.g.: sudo vi /etc/avahi/services/airprint.service
    A quick sudo service avahi-daemon restart and you’re set!
    Step 5: Adding MIME types to CUPS (UPDATED)
    While debugging, I came across this post by Friedrich Hotz, and added the MIME types indicated and it now seems that CUPS supports AirPrint on its own? I’ve deactivated the avahi ‘.services’ files (sudo mv airprint.service airprint.service.off) and my Brother DCP-XXXX is still detected on my iPhone! And it prints too!

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

    Let me know if this helped you get a similar setup going on your own Pi.
    Looks like Duplex printing will be a battle for another day🙂
    LinuxRaspberry PiRaspbian

  9. Използването на принтер от мобилно устройство било то таблет или телефон е лесно когато имате принтер със такава поддръжка. Обикновенно тези принтери разполагат със връзка към безжична мрежа и (ама разбира се!) съответно са малко по-скъпи. Проблема възниква когато разполагате със по-стар принтер който е или само жичен (USB или Centronics) или принтер със безжична поддръжка, но по-стар модел.
    Под Android проблемите се решават сравнително по-лесно със Google Cloud Print. Изисква се браузър Chrome и регистриране на принтера във облака. Така можете да принтирате от целия свят на вашия принтер. Разбира се има уловка – трябва да се логнете във мобилното устройство и във Chrome със един и същи потребител. Ето и процедурата:
    Регистрираме принтера на настолния компютър тук chrome://devices/
    На мобилното устройство инсталираме Cloud Print
    И общо взето е това. Има няколко благинки:
    можем да използваме принтера от друг компютър. Хитрото е, че принтера тогава може да се намира във друг град, страна и даже континент. Разбира само от Chromeможем да си закупим по-модерен принтер със поддръжка на Google Cloud Print. Текущите модели са налични ето тукможем да наблюдаваме заявките през интернет оттукможем да печатаме документи от Google Drive директноможем да печатаме директно към CUPS под Linux със използване на специализиран драйвер за него. Кода на драйвера може да бъде взет оттук или да използвате прекомпилиран пакет оттукИ тъжната новина – връзката става само и единственно през интернет. Ако няма интернет дори и във същата стая да се намира принтера ако не е вързан със кабел към компютъра ще е просто неизползваем. Същото важи и за мобилното устройство – дори и да е във същата безжична мрежа. Ако няма интернет няма да може да използва принтера.
    Под iOS нещата са малко по-различни. Тук най-лесния и удобен начин е когато принтера поддържа AirPrint през протокола Bonjour. Ако нямаме такъв принтер разбира се ще си го емулираме:
    инсталираме HandyPrint на macOS оттук. Под Windows ще трябва да се хакне ето така или оттук със по-новата версия. Отделно под Windows ще се наложи да инсталирате и Bonjour Print Services оттук.
    на мобилното устройство избираме иконката за споделяне (share) и ако приложението поддържа AirPrint принтера ще се появи във списъка. Няма никакви настройки
    Сега малко особенности:
    принтера трябва да се намира във същата локална мрежа със мобилното устройствоняма функция печатане през интернетможе да се печата дори и когато интернет липсва във локалната мрежаако имате принтер свързан със AirPort Extreme или AirPort Express то самия принтер трябва да поддържа AirPrint за да можете да го ползвате. Официален списък на поддържаните принтери през AirPort има тук и неофициални тук и тук. Но ще трябва да проверите дали и принтера поддържа AirPrint иначе от мобилно устройство няма да можете да го видите и използватеможе да се ползва CUPS и да се емулира подобен принтер. За повече информация как – тук, тук и тукРазбира се това са официалните начини. Има и алтернативи. Hewlett Packard поддържат стандарта ePrint използващ техните устройства. FedEx имат мобилно принтиране също тук – като след отпечатването можете да изберете да минете през техен офис за да го вземете или те да ви го доставят. Можете да използвате Printer Pro – оттук или някое от многобройните алтернативни приложения. Можете да видите дали производителя на принтера ви няма приложение: Samsung, Canon, Epson или други.
    Както виждате – има богат избор вече на пазара. А само преди няколко години използването на принтер от мобилно устройство беше мит. Вече е реалност.

  10. Came back to install this on the same computer after wiping the disc and installing a new debian-based distro. iPad with iOS 11.4

    Got error message about not finding a cups module. Rechecked issues on fontaine’s github site and someone mentioned that python-cups has to be installed.

    It wasn’t, on my system. After installing, the script worked immediately.

  11. I really liked finding this “how-to”. I got it going right a away. Printed just fine1 I’m using Ubuntu 16.04 (I know I need to upgrade), and it worked from my new ipad mini 4. A bit later, it could no longer find an “Airprint printer”, though an older iPad Air 2 still sees it just fine and prints without an issue. It’s driving me crazy. Any hint in the right direction would be appreciated greatly.

Leave a Reply