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

/etc/cups/cupsd.conf

Comment out Listen localhost:631 and add Port 631

then Allow access

/etc/cups/cupsd.conf

 

# 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 >

 

Restart CUPS

/etc/init.d/cups restart

 

Now you are able to access remotely x.x.x.x:631 and add the printer

 

Install AirPrint

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

/usr/share/cups/mime/local.convs

/usr/share/cups/mime/local.convs
image/urf application/vnd.cups-postscript 66 pdftops

 

/usr/share/cups/mime/apple.types

/usr/share/cups/mime/apple.types
image/urf urf (0,UNIRAST)

 

/usr/share/cups/mime/apple.convs

/usr/share/cups/mime/apple.convs
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)

/etc/modprobe.d/8192cu.conf
 
/etc/modprobe.d/8192cu.conf
# Disable power saving options 8192cu rtw_power_mgnt=0 rtw_enusbss=1 rtw_ips_mode=1
 

Connect from windows

http://server_ip:631/printers/printer_name

 

 

25 Comments so far:

  1. Congratulations.
    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,..

  2. 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?

  3. 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?

  4. 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.

  5. 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

  6. 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.)

  7. Hi, Tried a few procedures to get airprint working on my pi without success. Finaly tried yours and all is good.

    Thanks so much!

  8. 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!

  9. Brilliant! Been trying to get IOS devices to print for a week – your methods work on my openmediavault server (Debian base). Thanks

  10. 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?

  11. 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.
    Assistance welcome

    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

  12. 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.

  13. 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

  14. It just opens port 631. check the syntax, and interface.
    If you connect via wifi, it would be wlan0 instead ot eth0.

  15. 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.

  16. 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?

  17. 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 πŸ™‚

  18. 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.

    Thx
    Le

  19. 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.

    Blah!

    But thanks for you indulgence,
    Le

Leave a Reply to AndrewG Cancel reply

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

Posted by: lesorsier on

Tags: ,

seo reseller