15.4. Objective 4: Install and Configure Local and Remote PrintersIf you've been able to run the commands listed in Objectives 2 and 3, you already have the printing system installed on your system. However, if you don't have the package, you can get the source code from ibiblio.org (ftp://ibiblio.org/pub/linux/system/printing), along with the other software mentioned later in this Objective. You should be able to build the software simply using make followed by make install. The printing system implemented by the lpd suite is primitive by today's standards. It provides for queuing, administrative control, and some handling of special file formats but doesn't directly address the recent trend away from character-oriented printers to more programmable machines. Fortunately, the software is modular, making its foundation easy to build upon, making it sufficient for most printing situations. 15.4.1. /etc/printcapThe printing process on Linux systems is governed by the printer capability file /etc/printcap. This text file defines all of the system's available print queues and their characteristics. The file is parsed by lpd, which ignores blank lines and comments beginning with a pound sign (#). Each printer definition in the file comprises one logical line, which is often broken up among multiple physical lines in the file using the \ line-continuation character. The definition itself is made up of fields delimited by colons. The first field, which begins in the first column of the file, holds the system name for the printer, such as lp. This field may contain aliases for the printer name separated by vertical bars. The rest of the fields in the definition hold mnemonics providing control flags and printer parameters. A basic printcap file defining a single printer is shown in Example 15-1. Example 15-1. A basic /etc/printcap file
In this example, printer lp is defined with the alias ljet. Either name could be used to print with this printer, using lpr -Plp or lpr -Pljet. lp is the default printer unless the user overrides it by placing a different name in the PRINTER environment variable. Note that the name of the printer has a trailing colon, followed by the line-continuation character. The subsequent lines contain printer attributes inside colon pairs. Some of the frequently used attributes are:
Both locally attached and remote printers will have queues defined in /etc/printcap.
15.4.2. FiltersThe printing process involves the rendering of various data formats by a single hardware device. Considering the wide range of possible formats (plain text, HTML, PostScript, troff, TEX, and graphics files such as JPEG and TIFF, just to name a few), affordable printers can't be expected to natively handle them all. Instead, Linux systems use a two-step transformation process:
This translation process and its intermediate data formats are depicted in Figure 15-1. Figure 15-1. Print data translation stepsEach print queue found in /etc/printcap can use a different input filter, as directed by the if=filter specification. This data translation process sometimes isn't necessary. For example, plain text can be printed directly by most printers, making the translation to PostScript and subsequent Ghostscript invocation unnecessary for basic output. Many printers, particularly laser printers, have a built-in PostScript interpreter, making Ghostscript unnecessary. These situations are detected and controlled by the filter program. A filter can be very simple. For example, you may have implemented a filter yourself by using a utility like pr to add a margin to a plain text print job before piping it into lpr. In practice, filters are conceptually similar, but are more complex and capable than this and usually handle multiple input formats. They do this by looking at the magic number at the beginning of the data file to be printed. (See the file command's manpage for more information on magic and magic numbers.) As a result, the filters are referred to as magic filters. Two such filters are APSfilter and magicfilter. Your familiarity with both filters is required for Exam 102. 15.4.2.1. APSfilterThis popular filter program accepts files in the PostScript, TEX DVI, ASCII, PCL, GIF, TIFF, Sun Raster files, FIG, PNM (pbmplus), HTML, and PDF formats. As mentioned earlier, APSfilter and the other software discussed here can be found at ibiblio.org. After downloading APSfilter, the compressed tarfile should be unpacked in /usr/lib. Then, simply invoke cd apsfilter and run the installer, ./SETUP. This interactive program presents a menu-based installation, where you direct such things as the Ghostscript printer driver selection, the choice of printer interface (such as /dev/lp0), the default print resolution, the use of color, and the output paper format. It then creates new printer entries in /etc/printcap, as well as creates new printer spool directories, and sets file permissions and ownership. It also compiles a few utilities necessary for the proper use of the filter. Once APSfilter is installed, your /etc/printcap will look something like that shown in Example 15-2. (SETUP makes a backup copy of /etc/printcap called /etc/printcap.orig before creating its new printcap file.) Example 15-2. The APSfilter /etc/printcap description
As you can see, the installation creates three printer definitions, each with multiple aliases and each using the same output device. This allows some degree of control over the filter, because the selection of the queue implies specific print parameters. The first definition (ascii) is intended to allow the user to force the printing of plain text even if the data is a PostScript program. The second entry (lp, the default) is the standard magic APSfilter, which tries to identify the data type itself. The last definition allows users to force APSfilter to send raw data directly to the printer with no intervention. This can be useful, for example, if you wish to print a PostScript file's programming instructions. APSfilter also configures logging and accounting for each printer queue. Finally, the setup routine optionally prints a graphical test page to verify your installation. After APSfilter is installed, you must restart lpd to enable the new print queues: # lpc restart all or: # /etc/init.d/lpd stop # /etc/init.d/lpd start APSfilter allows for some controls in /etc/apsfilterrc (and the user file ~/.apsfilterrc). Examples of these controls are configuration for Ghostscript features, special control sequences for printers, and configuration for the use of a particular filter method. Although this file is beyond the scope of LPIC Level 1 Objectives, you should be familiar with it and its purpose.
15.4.2.2. magicfilterAnother filter you may wish to try is magicfilter, which can also be obtained from ibiblio.org. Unlike APSfilter, which is implemented as scripts, magicfilter is compiled from C and comes with a traditional configure; make; make install procedure. (See Chapter 4, "Objective 3: Make and Install Programs from Source," for additional information on how to install software.) Building and installing magicfilter is straightforward and shouldn't cause any difficulty. However, the installation does not automatically create print queues in /etc/printcap, although you can easily define one by setting the input filter to /usr/local/bin/magicfilter, as shown in Example 15-3. Example 15-3. The magicfilter print queue
15.4.2.3. Multiple filtersWhen a filter is installed, it is placed in a directory from where it can be called as needed. The printer definitions in /etc/printcap put the filter into service. Because you can create as many printer definitions as you like, it is possible to have multiple filters in place at the same time.
15.4.3. Remote lpd and Samba PrintersConfiguring your system to use a remote Linux printer (or other lpd device, such as a network-attached printer) can be as simple as adding a local printer. Two additional configuration variables are added to the printer definition in /etc/printcap to specify the remote host and the queue name on that host. For example: rlp:\ :sd=/var/spool/lpd/rlp:\ :rm=lphost:\ :rp=rlp:\ :mx#0:\ :sh:\ :if=/usr/local/bin/magicfilter: Here, this local print queue will send jobs to printer rlp residing on lphost. Since remote printers still have local queues, you must create the spool directory, in this example, /var/spool/lpd/rlp. Configuring a remote printer that's on a Windows network is also straightforward. (The Windows printer must be properly shared.) First, a local spool directory is created as usual, for example, /var/spool/lpd/winpr. Next, an /etc/printcap entry is added that looks something like this: winpr:\ :sd=/var/spool/lpd/winpr:\ :mx#0:\ :sh:\ :if=/usr/bin/smbprint : The input filter for this printer is smbprint, a utility from the Samba software suite. Finally, a .config file is created in the spool directory, which contains:
The service name and password are set in the Sharing dialog box on the Windows machine. The .config file might look similar to the following: server=WINBOX service=WINPR password="" After restarting lpd, you should be able to print text documents to the Windows printer.
|