AirPrint in Gentoo

I’m interrupting the series of posts about gold to post about something I was working on as part of a different job. More about gold will resume next week.

For one of my customers, I’m developing a private web application that would probably make most Free Software enthusiasts – not just the advocates – cringe. It is developed in ASP.NET, with a SQLServer backend, and is targeted at iPad users. While in general this looks like a bad combination for a Free Software developer, paid work is paid work, and even working on Windows has its upsides, namely learning about alternative approaches and the good and bad things about them, to make your software better — to be honest I’m not sure I dislike ASP.NET more than I disliked Hobo last year.

Putting the iPad to good use is also easy: I’m reading even those O’Reilly books that were previously cumbersome to read, PDFs like CJKV Information Processing which I bought last year and never went around to read, because of not being available in ePub format.

Let me say that, as a toy, the iPad is far from bad: Apple’s hands-on approach can be criticized, but the results for a naïve, jaded user are almost near perfection. On the other hand, I don’t think I’d trade my Milestone for an iPhone any time soon, even with all its troubles — the most bothersome issue is due to my CyanogenMod installation where the “hold call” button is pressed by my cheek while talking; it seems like I’m not alone and I’m now trying the method reported there to see if it helps.

While they really seem to have an app for everything, and their not-really-multitasking approach appears to work better than what I’m used to on Android, it is rough on the edges for the meddlers: I can’t install additional certificates (I can on Android); I can’t use an email address different than the GMail login (I can on Android); it doesn’t sync contacts on Google Contacts on the fly (Android does), and so on a few more “minor” things that I just love, in my Android.

But there is also one thing that the iPad can do and my Android can’t: printing. Of course it should be easy to do, especially given that Linux’s printing system is the same CUPS used by Apple – and actually, developed, given they bought the original developers! – but that’s not really the way they decided to do it. In a very environment unfriendly way, Apple decided that you can’t just use any printer with their iPad, you need to buy a new one, as they will not provide the AirPrint interface with older models.

You can guess that people already found out how to avoid that. I had saved a long time ago a post by Eric Sandeen on the topic, which later points to a GitHub project with a script that generates a service file for Avahi, which can then be used to advertise the printer properly.

But even with this it is far from being straightforward to deal with it. First problem I found is that the script needs the cups Python extension; this is not provided by net-print/cups[python] as I first expected – I since updated the USE flags’ description in the metadata.xml file: the interpreter flags are used for cups’s own CGI scripting support, which is definitely non-obvious – but rather by the dev-python/pycups package.

The next problem is that, because of technical limitations on the size of TXT records used in mDNS discovery – if you didn’t look up post and projects I have listed above, the AirPrint protocol is actually just the usual IPP as provided by cups, wrapped through mDNS with a custom record for exposing the printer’s features – some of the printer’s options are not exposed. One of those that is ignored is duplexing, but since my only real reason to print from the iPad is printing invoices, which I always print duplex – don’t get me started on why I should be printing invoices – I wanted to expose it. Luckily the generated Avahi service file is easy to fiddle with.

Next up, actually trying to print. Unfortunately there is one thing that could be a bit difficult to guess: CUPS validates the Host header passed (IPP is based on HTTP/1.1). By default, if you don’t fiddle with its configuration, what it looks for is the same hostname as set in the system, but what gets sent by the iPad is what it has found through mDNS/Avahi, which is the base host name followed by the .local domain. In my case that meant CUPS was expecting deepspace9.home.flameeyes.eu and it got deepspace9.local. Since the CUPS configuration is heavily inspired by Apache, just adding ServerName and ServerAlias should be enough… but it’s worth noting that when accessing CUPS through a browser, especially with SSL enabled, it will send the port number as well, so you should alias both hostname and hostname:631.

The takeaway of this all? Well, sometimes proprietary software solutions are not any better than Free Software — not that there is a good way to handle that for us as well, but it still shows its fragile support even using the same server software as the protocol’s creator.

7 thoughts on “AirPrint in Gentoo

  1. Certificates on iPad: I think if you send the certificate to yourself by email and open the attachment on the iPad it will ask you, if you want to install it… did on my iPhone…

    Like

  2. There is a way you can print from your mobile, but you need to use an enabled app, like Google Docs or similar, and also you need Chrome installed on your desktop. You can find more here:http://www.google.com/chrom…I tried it and it does work. :) I was surprised that it worked, to be honest, but it worked.

    Like

  3. Nice to know about the certificates.As for printing with Android — let’s just say I prefer Apple’s approach. Especially since that does not require me to keep a desktop computer running somewhere. Given that I actually put to suspend both my desktops (and the laptops) when I’m not using them, iPad printing is useful for that one reason.

    Like

  4. Damn, Flameeyes, you tricked me into reading the whole article due to the headline reading “Airplay”. But you one wrote about Airprint (which I – for my case – had already figured out long time ago).Now please write something about Airplay… :-).

    Like

  5. Ack I was definitely on acid the other day, I fixed the blog’s title and links now :(I haven’t looked into AirPlay yet to be honest, I have heard its name, but that’s about it… if I find something I’ll be sure to post it though.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s