Monday, 7 October 2019

Enabling AirPrint to legacy HP LaserJet printers using Debian 10

This guide will hopefully help you get AirPrint working on older HP LaserJet devices that do not natively support it.

On your Debian 10 server, install avahi-daemon (Bonjour) and CUPS (print queue) servers:

$ sudo apt install avahi-daemon cups

Add printer queue, replacing your.printer.hostname with host or IP of your printer, and set the description (-D) to whatever you want:

$ sudo lpadmin -p hp -D "HP LaserJet M1522nf MFP" -E -m drv:///sample.drv/laserjet.ppd -v socket://your.printer.hostname

Check if the sharing capability is enabled within CUPS and if not, enable it:

$ sudo cupsctl | grep share
_share_printers=0
$ sudo cupsctl --share-printers

Also enable sharing for the queue itself:

$ sudo lpadmin -p hp -o printer-is-shared=true

You can check the default settings for the printer using lpoptions. The defaults are displayed with an asterisk next to them:

$ lpoptions -d hp -l
PageSize/Media Size: *Letter Legal Executive Tabloid A3 A4 A5 B5 EnvISOB5 Env10 EnvC5 EnvDL EnvMonarch
Resolution/Resolution: 150dpi *300dpi 600dpi
InputSlot/Media Source: *Default Tray1 Tray2 Tray3 Tray4 Manual Envelope
Duplex/2-Sided Printing: *None DuplexNoTumble DuplexTumble
Option1/Duplexer: *False True

Here I have changed the paper size and default resolution systemwide:

$ sudo lpadmin -p hp -o PageSize=A4
$ sudo lpadmin -p hp -o Resolution=600dpi

You should now be able to see the mDNS entries using avahi-browse (in the avahi-utils package):

$ avahi-browse -at | grep -i hp
+   eth0 IPv6 HP LaserJet M1522nf MFP @ server              UNIX Printer         local
+   eth0 IPv4 HP LaserJet M1522nf MFP @ server              UNIX Printer         local
+   eth0 IPv6 HP LaserJet M1522nf MFP @ server              Secure Internet Printer local
+   eth0 IPv4 HP LaserJet M1522nf MFP @ server              Secure Internet Printer local
+   eth0 IPv6 HP LaserJet M1522nf MFP @ server              Internet Printer     local
+   eth0 IPv4 HP LaserJet M1522nf MFP @ server              Internet Printer     local

For fairly minimal effort, this setup seems to work quite well. Although printing is done via AppSocket/JetDirect, CUPS is smart enough to talk to the printer via SNMP to find out the printer status such as low toner or any errors. If it isn't already obvious, the Debian server will need to be on for the AirPrint function to work!