CUPS + AirPrint on Raspberry PI
Install CUPS and Enable Remote Access
apt-get install cups
Add Pi user to lpadmin group
usermod -aG lpadmin pi
Enable Remote Access
and add Port 631
then Allow access
# Only listen for connections from the local machine # Listen localhost:631 Port 631 < Location / > # Restrict access to the server... Order allow,deny Allow @local < /Location > < Location /admin > # Restrict access to the admin pages... Order allow,deny Allow @local < /Location > < Location /admin/conf > AuthType Default Require user @SYSTEM # Restrict access to the configuration files... Order allow,deny Allow @local < /Location >
Now you are able to access remotely x.x.x.x:631 and add the printer
apt-get install avahi-discover cups cups-pdf python-cups apt-get install hplip
Make your old printer AirPrint capable
/etc/init.d/avahi-daemon start mkdir /opt/airprint cd /opt/airprint wget -O airprint-generate.py --no-check-certificate https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py chmod +x airprint-generate.py ./airprint-generate.py -d /etc/avahi/services /etc/init.d/avahi-daemon restart ls /etc/avahi/services/
Add those files with this content
image/urf application/vnd.cups-postscript 66 pdftops
image/urf urf (0,UNIRAST)
image/urf application/pdf 100 pdftoraster
Open port 631
iptables -A INPUT -i eth0 -p tcp -m tcp --dport 631 -j ACCEPT iptables -A INPUT -i eth0 -p udp -m udp --dport 631 -j ACCEPT
Disable power saving (optional)
options 8192cu rtw_power_mgnt=0 rtw_enusbss=1 rtw_ips_mode=1
Connect from windows
previous - next
37 Comments so far:
Leave a Reply
Tags: AirPrint, CUPS
I was searching about 3 weeks for a solution with my canon-ts5050 printer. I have contacted canon and they returned their printer are only working in win and mac. But your way was right to print in raspbian. I am happy. Thank you.
glad to help,.. it was all about my 25 years old HP laser jet,.. it works much better then printers you can buy these days,..
So I was able to follow it halfway… I came to the section the files in the /mime/ folder, but I am not able to find any of those files. Do I need to create those files?
Yes, create them.
I just did and wow, it just works! Thanks for explanation!
so far this was the only method that made my airprint to work with raspberry but many times doesnt show to print or takes some time to find the printer. Any idea what could be the issue?
It is some network conflict most likely. Never google for it, so I have no proof, but it seems to me that some routers has problem with air print protocol. I had similar situation where I needed to reconnect to wifi in order to see printer. Then I changed my internet provider, got new router, and never have that issue again.
Tried this procedure with a pi 1B, Stretch and an HP LaserJet 5 connected with parallel to USB adapter. Used the Gutenprint cups driver. Can print from the pi and a Win 10 laptop. Airprint however gives a “filter Failed” error message in cups. double checked everything even rebooted but no luck. Anyone have any ideas
Hi, for my Debian system, this process worked to finally share my Samsung CLX6220fx colour laser as an airprint device without having to have a Mac. Thanks! (And I didn’t need to create the files, not on a Pi system.)
Hi, Tried a few procedures to get airprint working on my pi without success. Finaly tried yours and all is good.
Thanks so much!
This is great! I used these instructions on my Ubuntu 18.04 Server w/existing CUPS installation to allow my iPhone and iPad to print! That python script is clutch!
[…] implementations and could not get them to show up on my iOS device. After some digging I found this post on setting up AirPrint with a RaspberryPi which I installed locally on the NAS. I did not need […]
Brilliant! Been trying to get IOS devices to print for a week – your methods work on my openmediavault server (Debian base). Thanks
Thanks to this excellent post I was able to finally make a reliable Airprint Service for my DNP DS40 Dye Sub Printers.
However I am stuck in creating an avahi print service for a cups class that has two of those printers as members.
Tryin to print from iPad OS to this class always results in print error / print job stuck in iPad OS’s print tray.
Would you have a hint on what I could try different/additional to running airprint-generate.py after creating the class?
Print job from iphone is getting created in cups jobs list.
Print job from iPad is getting created in cups jobs list, with
message “/var/spool/cups/d00027-001 (object 8 0): object has offset 0”
Jobs are not coming out on printer.
iOS 13.3 iPhone
iOS 12.4.4 iPad
Raspberry pi model B serving as printserver for Brother HL-2240 series
Cups driver Brother HL-1250 – CUPS+Gutenprint v5.3.1
I tried this on FreeBSD. It works to print from a Mac, but not from iPhone. The iPhone says “Contacting printer…”, then “Preparing…”, then nothing. The job never appears in CUPS job list and I don’t see any error messages.
Same here, did you find any solution?
Thanks for thee excellent detailed procedure – must be an “old hand”.
Hate to cause you to switch to debugging mode after time has passed but the following failure occurs during the given sequence and I am getting airprint printer is offline. It’s not – I can print from the Pi to my Brother
[email protected]:/usr/share/cups/mime $ iptables -A INPUT -i eth0 -p tcp -m tcp –dport 631 -j ACCEPT
iptables v1.8.2 (nf_tables): Couldn’t load match `tcp’:No such file or directory
It just opens port 631. check the syntax, and interface.
If you connect via wifi, it would be wlan0 instead ot eth0.
Thx. Yeah, got the intent, but thought you’d recognize something strange about iptables installation / function. I’m running on Raspian Buster with the latest iptables, iptables-persistant, libip4tc0, libip6tc0, and libiptc0 reinstalled – same error. I looked these up by searching in synaptic for iptables modules that are instaalled.
Apparently current Buster distro has something fouled up w.r.t. iptables. Unless something strikes you I’ll continue searching for similar iptables failures. No joy so far.
Thx again for the excellent post.
Opening port 631 passed iptables cmd i/f with
–dport vice -dport
But airprint on my iOS client reports the printer is offline. It’s fine from the CUPS admin page. I can print from the host, and this is all after a reboot.
Any suggestions for approaching debugging the internal chain?
mime files was the critical part for me…check those, as well as permissions.
Avahi part also,.. I am not sure if it works anymore, and with which printers.
In my case, 25 years old HP laserjet 4l it worked 🙂
So, the drama continues. It appears that bonjour is properly connecting to CUPS daemon, but there appears to be a privilage issue with the “name” submitting the job to CUPS. I’m printing from an iPhone and it behaves as I would expect allowing me to select a printer that is exposed and receives the error back as expected.
The CUPS error log looks like:
D [time hack…] [Client 14] 2.0 Create-Job 3
D [time hack…] Create-Job ipp://raspberrypi.local.:631/printers/Brother_HL-2240_series
I [time hack…] Denying user “mobile” access to printer “Brother_HL-2240_series”…
D [time hack…] Create-Job client-error-not-authorized: Not allowed to print.
E [time hack…] [Client 14] Returning IPP client-error-not-authorized for
I was assuming that the job submission would come from the “pi” acct not “mobile”. I’m missing something about bounjour’s / avahi’s use of user name. Is there some translation table in one of the avahi configuration files? I cut and pasted from your sequence of cmds.
Well, that was quite unsatisfying. Got it working by adding the nonexistent user “mobile” to the CUPS printer’s user list.
This feels like Lisp. No arguement validation. If it works, fine.
But thanks for you indulgence,
Hi, first of all thank you guys for all the information regarding this topic! Rather special question here from my side though:
Have got everything up and running smoothly connecting and printing to various physical printers and PDF. However, my goal was to use the Raspberry Pi in combination with CUPS to route receipts from the payment app iZettle to a low cost thermal printer.
When wanting to print via this app, the following error occurs: UIPrintErrorDomain-Error 4 – as I mentioned printing from other, regular apps(Notes etc.) works flawlessly.
The customer service people there vaguely meant that only official AirPrint printers are able to be used with their app.
Do you guys know if there is a way to emulate official AirPrint compatibility within CUPS?
Thank you very much for your help and sorry for the rather specific question!
Best regards, David
I’m stuck in the “Make your old printer AirPrint capable”. The python script fails:
./airprint-generate.py -d /etc/avahi/services
Traceback (most recent call last):
File “./airprint-generate.py”, line 25, in
import cups, os, optparse, re
ModuleNotFoundError: No module named ‘cups’
Any clue? Thank you
# install python cups dependencies
sudo apt-get install python3-pip
sudo apt-get install libcups2-dev
sudo pip3 install pycups
sudo apt-get install python3-dev
cups has to be up and running
Hi! My old Brother DCP-357c is on the iOS list “AirPrint Brother_DCP-357C”. After tapping it says “Processing…” and on the printer screen “Receiving data” and nothing is printing… Any ideas? TY
try printing from another app. Some formats like PDF needs additional drivers sometimes…in other words, unsupported format.
Description: Brother DCP-357C
Driver: Local Raw Printer (grayscale, 2-sided printing)
I think the problem is driver… This printer is unsupported by CUPS. But… I working like a charm from Windows, Ubuntu and Mac – systems are installing drivers from the web.
Have you ever seen smth like this?
I am not sure, if windows and mac needs cups…but this airprint script use cups driver…so, try to find and install cups driver… I didn’t know that there is a printer that cups does not support:)
Thanks! *This* is the perfect guide!
This was great help!
I was stuck with Brother DCP-1610W…via network.
Did not find drivers for it. Was successful when using PCL:
Driver: Generic PCL Laser Printer (grayscale)
I’m trying to install this setup on an old Rpi running buster which involves Python 3 so I’ve found that to resolve the ModuleNotFoundError: No module named ‘cups’ error you need to change the instruction for install python-cups to install python3-cups instead. Now things are broken at the iptables entries for opening port 631. It would be a great help if someone could post the revised iptables instructions suitable for buster. This is my first time messing with iptables so I’m not really clear on whether I’m editing some config file somewhere or if I’m issuing a command to iptables to insert an entry (I suspect that this is the case). Thanks
Found the answer, it is sort of referenced above but I think what was posted got garbled… if you get a dport error on the iptables commands, (and you’re running buster), change the element within the command to a double-dash dport. ie replace -dport with –deport.