AirPrint to cups-pdf on Ubuntu

 

welcome_airprint2I got the 3rd generation iPad and needed to print some emails ? actually to save them as pdf. Easy enough to do on a Mac in Safari, but not an option in iOS 5.1. So, to get AirPrint working with cups-pdf on Ubuntu 10.04.4 LTS.

Avahi

Prior to this, I used airprint-generate.py to get AirPrint working with a regular printer. I manually duplicated the avahi service file for the cups-pdf printer from the regular printer created with the script. I imagine I could have used it again to create a avahi service file for cups-pdf.

/etc/avahi/services/AirPrint-PDF.service
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
 <name replace-wildcards="yes">AirPrint PDF @ server.local</name>
 <service>
 <type>_ipp._tcp</type>
 <subtype>_universal._sub._ipp._tcp</subtype>
 <port>631</port>
 <txt-record>txtvers=1</txt-record>
 <txt-record>qtotal=1</txt-record>
 <txt-record>Transparent=T</txt-record>
 <txt-record>URF=none</txt-record>
 <txt-record>rp=printers/PDF</txt-record>
 <txt-record>note=AirPrint</txt-record>
 <txt-record>product=(GPL Ghostscript)</txt-record>
 <txt-record>printer-state=3</txt-record>
 <txt-record>printer-type=0x80901c</txt-record>
 <txt-record>pdl=application/octet-stream,application/pdf,application/postscript,image/gif,image/jpeg,image/png,image/tiff,text/html,text/plain,application/openofficeps,application/vnd.cups-banner,application/vnd.cups-pdf,application/vnd.cups-postscript</txt-record>
 </service>
</service-group>

Of course, the key entry here, is the cups path to to printer:
<txt-record>rp=printers/PDF</txt-record>

I suppose it could be a path to a different cups server.

Cups-pdf

If not installed, install it on Ubuntu with:

apt-get install cups-pdf

Then, in cd /var/spool/cups-pdf/ we will have to make a link to your home directory. In this tutorial, I am using Dropbox to sync the generated pdfs. So, I created a link to a folder in my Dropbox folder for anonymous pdf files.
ls -la
total 16
drwxr-xr-x 4 root root 4096 2012-03-17 00:48 .
drwxr-xr-x 9 root root 4096 2012-03-17 00:15 ..
lrwxrwxrwx 1 root root 27 2012-03-17 00:38 ANONYMOUS -> /home/<user>/Dropbox/Docs/PDF
drwxrwxrwt 2 root lpadmin 4096 2012-03-17 00:46 ANONYMOUS-orig
drwxr-x--x 2 root lpadmin 4096 2012-03-17 10:32 SPOOL

Also, we need to change some settings in /etc/cups/cups-pdf.conf. Since this server is only for me, I don’t really have to worry about others, so I change the user output destination.
Out ${HOME}/Dropbox/Docs/PDF

I was also forced to change the AnonUser to my own account. Obviously, I would have liked to not have done this, but I had to, to get it to work.
AnonUser <youraccount>

Apparmor

I also had to change apparmor a bit as it wasn’t allowing cups to write files in my user directory.

/etc/apparmor.d/usr.sbin.cupsd

Find the lines with “{HOME}” and “PDF” in them and change to match the desired destination:
@{HOME}/Dropbox/Docs/PDF/ rw,
 @{HOME}/Dropbox/Docs/PDF/* rw,

Once that is done, restart apparmor, cups, and avahi. Log files for cups-pdf are at /var/log/cups/cups-pdf_log.

If you get a error like

[ERROR] failed to set file mode for PDF file (non fatal) (<path>/Test_Page.pdf)

Either you have filesystems permissions or app armor is causing problems.

UPDATE: See http://sysblog.sund.org/2012/10/ios-6-and-airprint-on-ubuntu/

Leave a Reply