AirPrint
Printing on Air
ByIf your home network includes a Linux machine, you have access to everything you need to share your printers on the network as AirPrint-enabled devices.
iOS version 4.2 was the first to give the Apple iPad and iPhone the ability to print – but only on printers that support the technology known as AirPrint. AirPrint devices are now available from all major manufacturers in every price and performance class, but many users are still wary of having to buy a new printer just to put something from their iPhone or iPad onto paper.
Luckily, if your home network includes a Linux machine, you have access to all the tools you need to share your printers on the network as AirPrint-enabled devices. AirPrint is based on the zero-configuration (Zeroconf) networking standard, which Apple markets under the brand name Bonjour. Linux has its own implementation of Zeroconf known as Avahi.
As early as 2011, Till Kamppeter modified the Common Unix Printer System (CUPS) implementation for the Ubuntu Natty and Oneiric versions so that connected AirPrint printers are directly available. If your distro doesn’t support direct configuration, it pays to know how to set up AirPrint support manually. In this article, I take a look at AirPrint with Linux.
CUPS
AirPrint is a technology that lets the device send PDF files to the printer. For this purpose, it sends information about the number of copies and page numbers that the user actually wants to print. A working installation of CUPS should be all you need to let iPad and iPhone find the network-shared printers and print to them.
Unfortunately, Apple has now removed some important features from CUPS that are not necessary on Mac OS X, because they are provided there by the Bonjour service. Fortunately, Linux reintroduces these missing features through Avahi, which includes the necessary functions.
CUPS configuration in Linux is described by numerous web sources. In this article, I assume a working version of CUPS is running on your system. Once the CUPS service is running, first check whether your printer is working by printing a test page. (Open a browser and enter the URL http://<hostname>:631.) You can reach this page from any other computer on the network. In the Printers tab below Management, you will see the command for outputting the test page.)
To share the printer on the network, make sure the /etc/cups/cupsd.conf file contains the appropriate entries. Listing 1 shows an example from the test system.
Listing 1: Example of /etc/cups/cupsd.conf
01 ServerAlias * 02 Listen *:631 03 Listen /var/run/cups/cups.sock 04 # Restrict access to the server... 05 <Location /> 06 Allow @LOCAL 07 Order allow,deny 08 </Location> 09 # Restrict access to the admin pages... 10 <Location /admin> 11 Order allow,deny 12 Allow @LOCAL 13 </Location> 14 # Restrict access to configuration files... 15 <Location /admin/conf> 16 AuthType Default 17 Require user @SYSTEM 18 Order allow,deny 19 Allow @LOCAL 20 </Location>
The first two lines are important here; they allow any client to access the server. These lax permissions facilitate attacks on the service. It is thus important to consider any changes you make.
Change the file accordingly and restart the CUPS system. On openSUSE, you can do the following:
sudo systemctl restart cups.service
On Ubuntu and other Debian systems, however, use the following command:
sudo /etc/init.d/cups restart
Now you should be able to find the printer from a Windows computer. To do this, Add a new network printer in the Control Panel and then type the address of the CUPS server and the name of the printer as the name of the shared printer (Figure 1).
Windows asks for the printer model to install the correct driver. If you see an Unable to connect message here, check your CUPS installation and the network share for the printer again.
Avahi
For Apple devices to be able to recognize the printer, you need to advertise it via a Bonjour broadcast on the network. To do this, set up an Avahi service. The configuration files for these services can be found in the /etc/ahavi/services directory. Listing 2 shows the AirPrint HP1220C.service file on our lab system.
Listing 2: AirPrint HP1220C.serviceconf
01 <?xml version='1.0' encoding='UTF-8'?> 02 <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> 03 <service-group> 04 <name replace-wildcards="yes">AirPrint HP1220C @ %h</name> 05 <service> 06 <type>_ipp._tcp</type> 07 <subtype>_universal._sub._ipp._tcp</subtype> 08 <port>631</port> 09 <txt-record>txtvers=1</txt-record> 10 <txt-record>qtotal=1</txt-record> 11 <txt-record>Transparent=T</txt-record> 12 <txt-record>URF=none</txt-record> 13 <txt-record>rp=printers/HP1220C</txt-record> 14 <txt-record>note=Raw Queue with driver HP Deskjet 1220c hpijs, \ 3.12.11</txt-record> 15 <txt-record>product=(GPL Ghostscript)</txt-record> 16 <txt-record>printer-state=3</txt-record> 17 <txt-record>printer-type=0x82b01c</txt-record> 18 <txt-record>pdl=application/octet-stream,application/pdf,\ application/postscript,image/gif,image/jpeg,image/png,\ image/tiff,image/urf,text/html,text/plain,\ application/vnd.cups-banner,application/vnd.cups-command,\ application/vnd.cups-pdf,\ application/vnd.cups-postscript</txt-record> 19 </service> 20 </service-group>
Admittedly, creating and modifying these service files manually for each printer on the system might not be everybody’s idea of fun. Luckily, developer Timothy J. Fontaine implemented a small Python script (Listing 3) that automatically creates these files for all CUPS printers on the system [https://github.com/tjfontaine/airprint-generate].
Listing 3: Executing Python Script
wget https://github.com/tjfontaine/airprint-generate/zipall/master unzip master cd tjfontaine-airprint-generate-fb98c1d/ ./airprint-generate.py mv AirPrint-HP1220C.service /etc/avahi/services sudo systemctl restart avahi-daemon.service sudo systemctl restart cups.service
The steps are easy enough: Just run the script without any parameters once for each printer; this gives you a file that you then copy to the /etc/avahi/services directory. After restarting Avahi and CUPS, you should be able to print from Apple devices without any problems.
Creating MIME Types
What we have looked at thus far will fail if you happen to have iOS version 6 or newer installed on your device. In this case, you also need to create new MIME types to associate incoming data correctly. This is fairly straightforward (Listing 4).
Listing 4: Creating MIME Types
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
Conclusions
In contrast to the popular workarounds using specialized printer apps, this approach does not require any intervention on the Apple device. You just use the existing print function. Figure 2 shows you what this process looks like on the iPad.
In just a few steps, you have prepared a CUPS server for printing via AirPrint. This saves you money, because not all printers support this technology out the box.
Moreover, the approach poses no specific requirements on the printer. The adjustments are made entirely on the Linux PC. In principle, this approach should work with any mini-server running embedded Linux, too.
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.
-
Plasma Desktop Will Soon Ask for Donations
The next iteration of Plasma has reached the soft feature freeze for the 6.2 version and includes a feature that could be divisive.
-
Linux Market Share Hits New High
For the first time, the Linux market share has reached a new high for desktops, and the trend looks like it will continue.
-
LibreOffice 24.8 Delivers New Features
LibreOffice is often considered the de facto standard office suite for the Linux operating system.
-
Deepin 23 Offers Wayland Support and New AI Tool
Deepin has been considered one of the most beautiful desktop operating systems for a long time and the arrival of version 23 has bolstered that reputation.
-
CachyOS Adds Support for System76's COSMIC Desktop
The August 2024 release of CachyOS includes support for the COSMIC desktop as well as some important bits for video.
-
Linux Foundation Adopts OMI to Foster Ethical LLMs
The Open Model Initiative hopes to create community LLMs that rival proprietary models but avoid restrictive licensing that limits usage.
-
Ubuntu 24.10 to Include the Latest Linux Kernel
Ubuntu users have grown accustomed to their favorite distribution shipping with a kernel that's not quite as up-to-date as other distros but that changes with 24.10.
-
Plasma Desktop 6.1.4 Release Includes Improvements and Bug Fixes
The latest release from the KDE team improves the KWin window and composite managers and plenty of fixes.
-
Manjaro Team Tests Immutable Version of its Arch-Based Distribution
If you're a fan of immutable operating systems, you'll be thrilled to know that the Manjaro team is working on an immutable spin that is now available for testing.