FreeBSD, CUPS and iPad printing
For a long time, I've struggled getting CUPS to work properly between my FreeBSD server and my Macs. I think I've finally figured it out.
I've installed these packages:
- print/foo2zjs (because I have a Samsung CLP 315; you might need a different driver package for your printer)
- net/avahi (as part of the larger Gnome packages)
The first task is to get CUPS to talk to the printer. Actually, the first task is to let cupsd accept commands from your browser. So open up /usr/local/etc/cups/cupsd.conf, and add Allow all to the <location /> block:
<Location /> # Allow remote access... Order allow,deny Allow all </Location>
While you’re at it, add this line, for example near the top of the file:
(CUPS, being an HTTP server, respects the Host: header in HTTP requests. Unfortunately, it doesn't really know about the Bonjour domain, so it rejects requests for host names that it thinks do not belong to the server, making print requests from Bonjour clients fail. Unless you're planning to set up a cluster of load balanced CUPS servers, ServerAlias * should just work fine to make CUPS feel responsible for any and all print requests that find their way to the server.)
Adding The Printer
Point your browser at http://yourserver:631 and navigate to the administration page. Click the Add Printer button there. At this point, your browser should ask you for a username and passwort. You'll need to log in with a system user that is in the wheel group.
- The first step in the Add Printer wizard has you select how CUPS will be communicating with the printer. My Samsung CLP 315 is hooked up via USB to a cheap network print server that speaks the plain TCP stream protocol on port 9100 (also known as JetDirect), so I selected that, and entered the URL: socket://hostnameofmyprintserver:9100.
- Next enter a name, a description and a location for this printer. The name is the queue name that you will use from the command line as well as from other IPP clients, so pick something short and meaningful, and easy to type. IPP clients like Macs show the description and location information to help you identify a particular printer; it's only ever displayed, and you never need to enter these into a client, so feel free to type away to your hearts content. Also make sure you check Share this printer to make it available on the network.
- The final step is to select the appropriate printer driver: first pick the maker, then try to find the model, or a close approximation. The Open Printing Printers List may help finding the right entry.
- After clicking Modify Printer, you should be presented with a short success message, and then be taken to the admin page for your newly created printer. From the Maintainance menu, pick Print Test Page to make sure that you can actually print successfully. If this fails, it's down to parsing error logs (/var/log/cups) and Googling.
Enabling Remote Printing
From CUPS’ main Administration tab, check the two options Share printers connected to this system and Allow printing from the Internet, then click Change Settings. If you feel this will actually allow random people on the internet to print to your printer (because you don't have a firewall in front of your server), you'll need to read and apply the documentation for the Allow and Deny directives in cupsd.conf.
Printing from a Mac
If you have a Mac, you can use it to test network printing.
- Add a new printer, using the Internet Printing Protocol (IPP) protocol, enter the IP address or DNS name of your server, and the name of the printer queue on the server. It took me a long time to figure out that the queue name you have to enter here is actually the local part of the IPP URL! So if your printer name on the server is clp310, you need to enter /printers/clp310 here.
- Next, pick a printer driver for the new printer, and hit Add.
- Depending on your printer model, you might be asked to select which optional parts your printer has (like extra memory, additional trays or a duplex unit).
Now you're ready to print a test page from your Mac. Simply hit TextEdit or similar.
After having tested printing successfully, you can remove the printer again, as we're about to enable automatic discovery.
The final step is to enable your new network printer to be auto-discovered through the magic of Bonjour. CUPS should be able to tell avahi (the Bonjour agent) that information automatically, but that option appears to be broken in CUPS 1.4.6. Luckly, you can easily tell avahi what to announce:
<?xml version="1.0" standalone='no'?> <!DOCTYPE service-group SYSTEM "avahi-service.dtd"> <service-group> <name>clp315</name> <service> <type>_ipp._tcp</type> <subtype>_universal._sub._ipp._tcp</subtype> <port>631</port> <txt-record>txtver=1</txt-record> <txt-record>qtotal=1</txt-record> <txt-record>rp=printers/clp310</txt-record> <txt-record>ty=Samsung CLP 315</txt-record> <txt-record>adminurl=htt p://yourservername:631/printers/clp310</txt-record> <txt-record>note=Wohnzimmer Cat & Stefan</txt-record> <txt-record>priority=0</txt-record> <txt-record>product=Samsung CLP 315</txt-record> <txt-record>printer-state=3</txt-record> <txt-record>printer-type=0x801046</txt-record> <txt-record>Transparent=T</txt-record> <txt-record>Binary=T</txt-record> <txt-record>Fax=F</txt-record> <txt-record>Color=T</txt-record> <txt-record>Duplex=F</txt-record> <txt-record>Staple=F</txt-record> <txt-record>Copies=T</txt-record> <txt-record>Collate=F</txt-record> <txt-record>Punch=F</txt-record> <txt-record>Bind=F</txt-record> <txt-record>Sort=F</txt-record> <txt-record>Scan=F</txt-record> <txt-record>pdl=application/octet-stream,application/pdf,application/postscript,image/jpeg,image/png,image/urf</txt-record> <txt-record>URF=W8,SRGB24,CP1,RS600</txt-record> </service> </service-group>
In /usr/local/etc/avahi/services, create a new file myprinter.service (the actual name does not really matter), and paste the above. Of course, you will want to change a couple of entries in there:
- name: whatever you want displayed on the client. However, it's limited to certain characters.
- rp=printers/myqueuename: the local part of the IPP URL for your printer
- ty=SomePrinterModelName: a string identifying your make and model of printer; I'm not sure any client uses this acutally
- product=SomePrinterModelName: same as ty.
- adminurl=fullUrlOfCupsAdminPage: the full URL for the admin page for your print queue. You can go there in your browser, but clients can issue special requests to manage the queue and query it's status.
- note=aNoteToDisplay: random text that helps a user to identify this printer; basically the same information as the location for the printer in CUPS.
Save the file; avahi will pick up the (new) contents automatically. To see if the announcement has been registered, run avahi-browser -t _ipp._tcp; that will show you all printers being announced on your network.
And you’re done! Bonjour clients should now see the printer, and should be able to print to it.