Understanding the CUPS Printing System


Understanding the CUPS Printing System

In Red Hat Linux, with the CUPS printing system, the user’s view of printing is based on the basic printing commands: lp, lpr, lpq, lprm, and lpc status. A bit more information will help you understand how printing works behind the scenes. As with so many things in Linux, support for the CUPS printing system is all a matter of having the right files in the right places. This becomes apparent after you have configured Linux for networking and have set up dial-in modems, for example. In each case, you have to make sure that several configuration files appear in the correct places. The printing environment has the same requirement: configuration files that specify how printing occurs.

Although nowadays you can use graphical configuration tools to set up services such as printing and dial-up networking, it is useful to know the names of the text-configuration files because you can then fix problems even if you do not have access to a graphical login.

If you have experience with MS-DOS from a long time ago, you might have printed files by simply copying them to the printer port (LPT1, for example). You might think that a similar approach is good enough for Linux. As you see in the next section, such a brute-force approach to copying a file to the physical printer port is not appropriate for a multiuser system such as Linux. You need a way to queue print jobs and to have a separate printing process take care of the printing.

Copying to the Printer: Brute-Force Printing

If you have a printer connected to the /dev/lp0 parallel port, you can print a text file simply by sending the file to the printer with the following command:

cat webstat.txt > /dev/lp0

This command indeed produces a printout of the file webstat.txt, provided that the following conditions are true:

  • You are logged in as root (Linux allows only root and certain processes direct access to physical devices, such as printers).

  • The printer is connected to the /dev/lp0 port, powered up, and online.

The problem with copying a file directly to the printer device is that the command completes only when the copying (which, in this case, is equivalent to printing) is completed. For a large file, this process can take a while. In fact, if the printer is not turned on, the command appears to hang (if this happens, just press Ctrl-C to abort the command).

Printing the CUPS Way

On a multitasking and multiuser system such as Linux, a better way to print is to spool the data and schedule the printing: send the output to a file, and have a separate process send the output to the printer. That way, you can continue with your work while the printing takes place in the background. In addition, if your system has more than one user, everyone can print on the same printer, without worrying about whether or not the printer is available; the background printing process can take care of all the details.

That’s how the CUPS printing environment works. Users use a client program—lp or lpr—to send the files to be printed to a server called cupsd—the printer daemon—over a TCP/IP connection. The cupsd server then queues the files, filters the file (to get them ready for the printer), and sends them to the printer.

Although you typically have only one printer connected to your PC, one advantage of the CUPS printing system is the capability to print on a printer connected to another system on a network. Printing to a remote printer is handled in the same fashion as printing to a local printer; the local cupsd daemon simply sends the files to the remote system’s server.

As explained earlier, the user-level programs for spooling a file are lp and lpr. When lp or lpr runs, it sends the data to the cupsd server that manages the specified print queue. Other user-level commands for working with print queues are lpstat, lpq, cancel, lprm, and lpc. The program that completes the CUPS printing environment is the CUPS scheduler: cupsd.

In addition to the commands lpd, lpr, lpq, lprm, cancel, and lpc, the configuration files in /etc/cups directory play a crucial role in the CUPS printing environment. The “Understanding the CUPS Configuration Files” section describes the key configruation files.

Understanding the CUPS Configuration Files

You can learn a lot about the CUPS configuration files by examining the entries in various configuration files that the Red Hat printer configuration tool creates when you set up a new print queue. The CUPS configuration files are in /etc/cups directory.

Consider the example of adding a new print queue named Office-ES600 for an Epson Stylus Color 600 printer that is connected to the parallel port of the PC. Here are the files that contain information about this print queue and the printer model:

  • /etc/printcap—This file used to be the printer capabilities database and was very important to the LPD print spooler that used to be popular before CUPS came along (not that I miss LPD; CUPS is much better). CUPS generates single entry in the /etc/printcap file for each printer. For example, here is the /etc/printcap file that CUPS generates for a print queue named Office-ES600 (the details of the printer are in the /etc/cups/printers.conf file):

    # This file was automatically generated by cupsd(8) from the
    # /etc/cups/printers.conf file.  All changes to this file
    # will be lost.
    Office-ES600:
  • /etc/cups/printers.conf—This is the printer configuration file with entries for each print queue. The information includes the device where the printer is connected and other parameters of the queue. Here is the entry for the Epson Stylus Color 600 printer:

    <DefaultPrinter Office-ES600>
    Info Created by redhat-config-printer 0.6.x
    DeviceURI parallel:/dev/lp0
    Location Epson Stylus 600
    State Idle
    Accepting Yes
    JobSheets none none
    QuotaPeriod 0
    PageLimit 0
    KLimit 0
    </Printer>
  • /etc/cups/cupsd.conf—This is the configuration file for cupsd, the CUPS print scheduler. The syntax of the configuration file is similar to that of Apache httpd, the Web server (see Chapter 14 for a description of Apache httpd configuration). The similarities with the Apache httpd configuration files are to be expected because cupsd is also an HTTP server. Here are the entries in /etc/cups/cupsd .conf for the print queue names Office-ES600:

    <Location /printers/Office-ES600>
    Order Deny,Allow
    Deny From All
    Allow From 127.0.0.1
    AuthType None
    </Location>
    <Location />
    Order Deny,Allow
    Deny From All
    Allow From 127.0.0.1
    </Location>
    Browsing Off
    Listen 127.0.0.1:631

    There are many more directives in the /etc/cups/cupsd.conf file that apply all print queues managed by the cupsd server.

  • /etc/cups/lpoptions—This file stores the default option settings that apply to all print jobs when you create a print queue as root. Note that users can specify other options when they print with the lp commands. Here is the /etc/cups/ lpoptions file with the default options for the Office-ES600 printer:

    Dest Office-ES600 page-bottom=36 cpi=12 lpi=7 scaling=100 page-right=36 page-left=36 wrap=true page-top=36
  • /etc/cups/ppd—This is a directory that contains the PostScript Printer Description (PPD) file for the Epson Stylus Color 600 printer in a file named Office-ES600 .ppd (the name I had assigned to that print queue). Each PPD file is a text file containing information about the printer capability (similar to the old /etc/ printcap file in intent, but PPD files have much more detailed information). Here are the first few lines from the PPD file /etc/cups/ppd/Office-ES600.ppd:

    *PPD-Adobe: "4.3"
    *%
    *% For information on using this, and to obtain the required backend
    *% script, consult http://www.linuxprinting.org/ppd-doc.html.
    *%
    *% PPD-O-MATIC generated this PPD file. It is for use with all programs
    *% and environments which use PPD files for dealing with printer capability
    *% information. The printer must be configured with a Foomatic backend
    *% filter script. This file and the backend filter script work together to
    *% support PPD-controlled printer driver option access with arbitrary free
    *% software printer drivers and printing spoolers.
    *%
    *% You may save this file as 'Epson-Stylus_Color_600-gimp-print.ppd'
    *%
    *%
    *FormatVersion: "4.3"
    *FileVersion:   "1.1"
    *LanguageVersion: English
    *LanguageEncoding: ISOLatin1
    *PCFileName:    "GIMP-PRI.PPD"
    *Manufacturer:  "EPSON"
    *Product:       "Stylus COLOR 600"
    *cupsVersion:   1.0
    *cupsManualCopies: True
    *cupsModelNumber:  2
    *cupsFilter:    "application/vnd.cups-postscript 0 cupsomatic"
    *ModelName:     "Epson Stylus Color 600, Foomatic + gimp-print"
    *NickName:      "Epson Stylus Color 600, Foomatic + gimp-print"
    *ShortNickName: "Epson Stylus Color 600"
    *PSVersion:     "(3010.000) 550"
    *PSVersion:     "(3010.000) 651"
    *PSVersion:     "(3010.000) 652"
    *PSVersion:     "(3010.000) 653"
    *PSVersion:     "(3010.000) 704"
    *PSVersion:     "(3010.000) 705"
    *LanguageLevel: "3"
    *ColorDevice:   True
    *DefaultColorSpace: RGB
    *FileSystem:    False
    *Throughput:    "1"
    *LandscapeOrientation: Plus90
    *VariablePaperSize: False
    *TTRasterizer:  Type42
    
    *HWMargins: 0 0 0 0
    *VariablePaperSize: True
    *MaxMediaWidth: 100000
    .... many lines deleted ...
    

    That should give you an idea of the kind of information stored in PPD files. You don’t have to understand or prepare the PPD files manually. CUPS generates the PPD file automatically from descriptions in the Foomatic printer drivers that come with Red Hat Linux (described later in this chapter).

As this example shows, for each print queue it manages, CUPS needs a considerable amount of information stored in multiple configuration files. So far, I have shown you only the configuration files affected by the definition of a new print queue. It’s helpful to know the full extent of the configuration files, understand their purpose, and have a rough idea of what each of these files contain.