Jérôme Belleman
Home  •  Tools  •  Posts  •  Talks  •  Travels  •  Graphics  •  About Me

Printer Options with CUPS

8 May 2017

Regular users can set printer options without any privileges, and do so on the fly with arguments passed to lp or configuration files in their home directory.

1 Finding available options

I'm not fond of graphical user interfaces, but one thing I confess they're good at is showing you at a glance what you can do. Certainly, I've more than once been missing an overview of what options I can use with my printer and pass the lp command. To make matters worse, options and their available values change from printer to printer.

How pleased I was when I stumbled upon the lpoptions command and its -l switch which lists all the available options the printer supports:

lpoptions -d hp -l

... where -d hp specifies a given printer known to my system – one called hp here. And for the sake of completeness, I probably ought to mention that getting a comprehensive list of printers available to your system can be done with the following command:

lpstat -a
hp accepting requests since Mon 8 May 2017 08:34:58 PM CEST

Coming back to lpoptions -l, you'll find as you get to use various printers, how instrumental a tool that is as some options as common as the resolution may be referred to in the most unpredictable ways. I once had to work with a Brother printer which didn't have any option remotely called resolution. However, paging through the available options, I could find one called Print Quality. Puzzled as to what it might mean, I took a look at the PPD file and found that it turned out to set nothing more than the resolution, such that its value Fine mapped to a 600 dpi and SuperFine mapped to 2400 dpi.

If anything, that's another lesson learned, then, when it comes to finding available options for your printer: don't be afraid of looking at its definition under /etc/cups/ppd.

2 Passing options to lp

You'll find that the output of lpoptions -l looks like:

Quality/Printing Quality: draft *normal
ColorMode/Color Mode: *Color Monochrome

It's a list of one-line key/value pairs of sorts, with different names for the keys mapped with a colon to all the supported values. It's not hard to guess that the option name that you'll need is the one without spaces, i.e. the left-hand one, for the simple reason that it'd be too inconvenient to use the one with spaces in a command line. (Although, for all I know, maybe the option name with spaces works too if you properly protect it with quotes. Never bothered to try it, in fact.) It's not hard to guess either that the default value is highlighted with a star.

From there, it's just a matter of using this information to pass those printer-specific options to lp, e.g. printing the foo document in black and white, here:

lp -o ColorMode=Monochrome foo

3 Setting options in a file

It's all very nice to pass lp options on the fly, but the command has the nasty habit of silently ignoring them if you get the option name or its value wrong. And they are easy to get wrong. Being able to set options once and for all in a file can reveal rather handy, from that perspective.

It's something you can do editing ~/.cups/lpoptions, with a line for each printer, following each of their name with a list of option name/value pairs, as follows:

Dest hp ColorMode=Color PageSize=A4 Resolution=1200x1200dpi
Dest brother PrintQuality=SuperFine

Again, it's probably best to use the option name that doesn't have spaces in it, i.e. the left-hand one in what lpoptions -l shows you. Note that the similar /etc/cups/lpoptions file lets a system administrator set system-wide options the same way.

4 References