Setting up Airprint on QNAP NAS with Canon MX 870 MFC

I recently bought a QNAP TS-219 II NAS and am quite happy with it. The best thing is, that you can log in via SSH and do your own stuff. This own stuff includes installing packages using ipkg and even compiling your own code. It may not be as nice as your Ubuntu build environment, but still handy.

My Canon MX 870 multi functional device does have Ethernet and Wifi, but no Airprint support. Since the NAS is on 24/7 anyway, it is the ideal negotiator between my iOS devices and my printer. Unfortunately, the gutenprint version on the NAS is too old to support my (and many other Canon) printer – so we have to update.

To find out whether your printer is supported by gutenprint, look at the Supported Printer Page. If it is supported, you are lucky. However, it is still possible, that your *current* version of gutenprint is too old. You can find your current version of gutenprint like so:

$ ipkg list | grep gutenprint
cups-driver-gutenprint - 5.2.6-1 - CUPS driver from Gutenprint.
gutenprint - 5.2.6-1 - Gutenprint.

Now go and look in the Release Notes (change the link to the latest version, start from here) of gutenprint, if support for your priner has been added on a version that is newer than the currently installed version. My printer became supported in version 5.2.7 so I had to upgrade. If your printer is supported in your release, skip directly on to Enable Airprint.

This blog post is based on the superb tutorial in the synology forum by tomas123. I had to change some elements in the (original german) tutorial to make it run on QNAP devices as well.

Installing OptWare

To do the following, you will need to have “OptWare” installed. Do that in the “QPKG Center” in the QNAP Webinterface. After installing it, you have to enable it. Furthermore, please enable the SSH access to your device.

Setting up the Build Environment

To build your own code on the QNAP, you will need compilers and other handy stuff. So first of all, log into your NAS via SSH:

$ ssh admin@NAS

Now install all necessary packages

$ ipkg update
$ ipkg install optware-devel make autoconf libtool automake gcc perl grep gawk popt sed

This will take a while, but it is worth the wait. Now, I had to do a couple of additional steps to get anything to build.

Fix automake to avoid using threads in Perl

Open /opt/share/automake-1.12/Automake/Config.pm and set perl_threads to 0.

$ vim /opt/share/automake-1.12/Automake/Config.pm

Go to line 35 and change it to match this:

our $perl_threads = 0;

Fix autoconf to use the correct path to automake

Open /opt/bin/automake and modify the path to automake.

$ vim /opt/bin/automake

And now change line 5228 to match the following:

my $traces = ($ENV{AUTOCONF} || '/opt/bin/autoconf') . " ";

Set a proper working path

This step is necessary, since the default PATH setting lets all tools look first in /bin and /sbin. However, the busybox tools setting there do not have the functionality that we need and many build scripts, etc. will fail. Therefore, open /etc/profile in your editor and navigate to line 52.

$ vim /etc/profile

Make sure, that /opt/bin and /opt/sbin are prepended to the PATH. To put it simple, make the line look like this:

export PATH=/opt/bin:/opt/sbin:$PATH

Now log out and reconnect to the NAS via SSH for the changes to take effect!

Install CUPS

First of all, install the OptWare included version of CUPS and the Webinterface:

$ ipkg install cups cups-doc cups-dev

Then stop CUPS to avoid doing any damage.

$ /etc/init.d/cupsd.sh stop

Download, Build and Install Gutenprint

Now, we can download the latest version of gutenprint. I have downloaded version 5.2.29, but I guess that newer version should also work. You can find the download archives on the sourceforge project page. The direct download to the version that I have used is this. If you need support for newer printers (the last release is from 2012), then go fo the latest CVS version.

$ wget "http://sourceforge.net/projects/gimp-print/files/gutenprint-5.2/5.2.9/gutenprint-5.2.9.tar.bz2/download"

Unzip the archive and build:

$ tar -xvjf gutenprint-5.2.9.tar.bz2
$ cd gutenprint-5.2.9
$ ./autogen.sh
$ ./configure CC="/opt/bin/gcc -std=gnu99 -I/opt/include -L/opt/lib" --prefix=/opt --includedir=/opt/include --with-cups=/opt --disable-cups-ppds --disable-cups-level3-ppds --without-foomatic --disable-libgutenprintui2 --disable-nls --disable-static
$ make
$ make install

Make the Init Script start our CUPS

Open /etc/init.d/cupsd.sh in your editor

$ vim /etc/init.d/cupsd.sh

And change line 220 to match the following:

/opt/sbin/cupsd -c /etc/config/cups/cupsd.conf

Start CUPS

/etc/init.d/cupsd.sh start

Now you should be able to access the webinterface of CUPS via:

http://ip-of-your-nas:631/admin

Log in with the admin account of your QNAP.

Install Canon Network drivers (only if you want to connect to your printer via Ethernet instead of USB)

If you want to connect your printer and your NAS via Ethernet, you will need the canon network drivers. If you connect directly via USB, I guess you can skip this step. I have to confess though, that I did not try it without Ethernet. I also suspect, that this step is optional, if you will install your printer without using the Canon network printer way using regular LPD and a fixed IP.

You can get the necessary source directly on the sourceforge project page. I have used the latest version 1.2.1, but I guess that newer version will work equally good. The direct download link is here.

So, go to your terminal, download, unzip, configure and build:

$ wget http://sourceforge.net/projects/cups-bjnp/files/cups-bjnp/1.2.1/cups-bjnp-1.2.1.tar.gz/download
$ tar -xvzf cups-bjnp-1.2.1.tar.gz
$ cd cups-bjnp-1.2.1
$ ./configure --prefix=/opt
$ make

To install the tool, copy it into the cups folder:

$ cp bjnp /opt/lib/cups/backend/

Restart CUPS:

$ /etc/init.d/cupsd.sh restart

Install the Printer – Canons way

I have to admin, that I do not know the advantage of doing it this way. For me, it seems like a stupid proprietary way – but I will guide you through it anyway. If you are more like me, you will probably use the LPD way in the next section.

Go to the Webinterface of your CUPS:

http://ip-of-your-nas:631/admin

Log in with the admin account of your QNAP. Navigate to “Add Printer” and select “Canon network printer”.

FIXME

Install the Printer – the LPD way

Straight forward, but you will need to know the IP address of your printer. However, knowing the address is always a good idea. You can find it out either via your routers webinterface (if you are lazy and do not want to get up) or you go to the printer and figure it out via the display and the menus.

Once you have your address, go to the Webinterface of your CUPS:

http://ip-of-your-nas:631/admin

Log in with the admin account of your QNAP. Navigate to “Add Printer” and select “LPD/LPR-Host oder -Drucker” (or the english equivalent thereof). Enter the following address into the next textfield:

lpd://ip-of-your-printer/L1

On the next page, enter your information about the printer and do not forget to enable sharing it! Now select the appropriate driver and you are done.

Enable Airprint

Install dependencies

The following packages are necessary to run python and to allow PDF conversion:

$ ipkg install python26 ghostscript

Install pycups

To enable Airprint, we will use the airprint-generate.py. For this, we also need the pycups library. I have used version 1.9.62 but I guess that newer version will also work.

$ wget http://pypi.python.org/packages/source/p/pycups/pycups-1.9.62.tar.bz2
$ tar -xvjf pycups-1.9.62.tar.bz2
$ cd pycups-1.9.62
$ python2.6 setup.py install

Install airprint-generate.py

Download the script:

$ wget --no-check-certificate https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py
$ chmod +x airprint-generate.py
$ python2.6 airprint-generate.py

A service file for your printer has been generated. Copy it to the folder where avahi looks for them:

$ cp YOUR-PRINTER-FILE.service /etc/avahi/services

And restart avahi:

/etc/init.d/avahi.sh restart

Add the proper mimetypes for iOS 6

iOS 6 needs mimetypes that are non standard on the QNAP. For more information see here and here. To fix this, manually crate the following files:

/opt/share/cups/mime/airprint.types

#
# "$Id: $"
#
# AirPrint type
image/urf urf string(0,UNIRAST<00>)
#
# End of "$Id: $".
#

/opt/share/cups/mime/airprint.convs

#
# "$Id: $"
#
# AirPrint
# Updated list with minimal set 25 Sept
image/urf application/pdf 100 pdftoraster
#
# End of "$Id: $".
#

Restart CUPS afterwards:

/etc/init.d/cupsd.sh restart

Try printing with iOS

If it is not working, check the individual steps for anything that went wrong.

In any case, please leave a comment with feedback!

Leave a Comment

Your email address will not be published. Required fields are marked *