Printing

StanislavšIevlev

Introduction

The electronic document workflow has been constantly becoming stronger over the recent years. But the “hardcopy”, the paper copy of a document, remains as relevant as ever. As soon as a user sets up a computer, he or she usually starts installing a printer. In this chapter you will find out how printing is set up in ALT Linux 2.3 Compact distribution, what obstacles await you along the way and how they may be overcome. First, let us discuss several general topics that will shed light on issues of printing in Linux.

What Types of Printers Are There?

Engineering thought does not ever pause for a moment: since the time when the first printing device had been invented, a great number of new technologies were tested and introduced. At the present moment the following printing technologies are the most commonly used:

Matrix Printers

Matrix printers are becoming outdated and slowly growing out of use, but, with their amazing simplicity and reliability, they are still taken advantage of. Problems with setup of this type of printers are very rare indeed.

Laser Printers

Laser printers have high printing speeds and are irreplaceable in the offices of all types of organizations. There are many models, but, fortunately, the majority have a “native” driver, or a compatible one.

Jet Printers

The main motto of jet printers is “Cheap and Colorful”. Because no definite leader exists in this industry, a variety of standards continues to flourish, and the likelihood of owning a very exotic printer, from the perspective of Linux, is high enough.

GDI or Windows Printers

Cheap by Any Means Possible”. These printers use computer resources instead of doing things themselves. Problems are highly likely because the working protocol of a printer is often proprietary. Fortunately, several models with interfaces resembling the interface of fully functional printers exist, allowing to perform low-resolution printing.

Where Is the Printer Driver?

If you ever had a chance to work with Microsoft Windows, then you should know very well that a floppy or a compact disk with a driver needed to set up printing is supplied with each printer. Most unfortunately, in the world of UNIX/Linux, no single driver standard has been agreed upon as of today. At the present time, the ghostscript package made by the Aladdin Software company, is used as the de facto standard.

What Is ghostscript?

ghostscript (abbreviated as GS from now on) is a program that transforms vector format into raster format (RIP). It accepts documents in the PostScript or PDF formats and outputs documents in a language understandable to a specific printer model or generates graphical images of the pages. Most Linux programs form documents in the PostScript format, and thus it turns out that the use of GS is sufficient to ensure printing from applications.

What Is PostScript?

PostScript is a real programming language used to describe the contents of a page. For instance, the following series of commands may be used: move to location X, print the word Y, change the active font to Z. There exist models of printers capable of interpreting PostScript directly. For the rest of printers, a mediator is needed, and GS plays this role successfully. You may ask, how can such a large number of printers be supported? The key to the issue is the fact that there are much fewer printer languages than there are actual printer models. For example, the well-known HP LaserJet 4, 4L, 5, 5L, 6, 6L, 1100 and 2100understand” the same PCL5 language. If you are not afraid of these terms and wish to see which language drivers your GS supports, issue the following command: gs --help. You may learn, for instance, that the ljet4 driver serves the line of printer models mentioned above.

Now it should become clearer to you how printing works in any Linux distribution: a program forms a document in the PostScript language, GS translates it into the language of the printer installed in your system and passes the baton over to the printer.

But this is not nearly all. What if you need to send a document to a printer installed on another computer or to print several documents at once and there is no time to wait until each one of them is served by ghostscript and yields way to the next one? All of these tasks are accomplished by the so-called print server or spooler, which manages printing queues. The term “spooler” reflects the essence of the object more precisely, and so from now on we will simply use this term.

lpd Spooler

In UNIX, lpd (Line Printer Daemon) is the standard spooler. It consists of the lpd server and a set of client programs to work with it. We are primarily interested in lpr, lpq and lprm.

lpr

lpr is used to send documents to the printer. If printing is already set up in the system, lpr my_file command can be issued to print the my_file document. If several printers are set up, for instance, printer1 and printer2, then to send a document to a specific printer, the -P printer_name parameter must be added. For example, in order to send a document to printer1, the command lpr -P printer1 my_file should be used.

lpq

lpq is used to view the queue of all tasks sent to the printer. To do this, issue the lpq command. If you are interested in seeing the state of a particular printer, you should add the key -P printer_name.

lprm

lprm deletes the last task from the queue (or the task having the specified identifier).

As you see, everything is brilliantly simple. Any program can send a document to the printer by executing the lpr command, so if you encounter a problem in printing from some office application, try issuing the command lpr my_file manually. If printing is performed successfully, then the problem is within the application itself - for instance, it may be forming an incorrect file in PostScript. Large graphical environments, such as GNOME and KDE, have their own common printing interfaces. So if all the applications in an environment have problems with printing, then something is wrong in the environment itself. Besides, if printing from one environment fails (let us say you are trying to print from Gedit in GNOME), try printing from another one (for instance, Kedit in KDE).

Like any server, lpd has its own configuration file. It looks quite awful (because of the age of this program), but it is nevertheless perfectly comprehensible. It is located in the /etc/printcap directory. The description of each printer is written on one line or on several lines, separated by the \ symbol immediately before the end-of-line symbol. The format of the record is the following:

<printer name> | <alternative name> | <one more name> : 
    : <parameter> = <value>::<parameter>:\
    :<parameter>#<value>

All parameters have two letters, the following are used most commonly:

lp (line printer)

The device to which the printer is connected. Example: lp=/dev/lp0

sd (spool directory)

The directory in which the tasks that are queued will be accumulated. Example: sd=/var/spool/lpd

lf (log file)

Error messages will be written to this log file. Example: lf=/var/log/lpd/messages

if (input filter)

The program through which the document will pass before being sent to the printer. GhostScript, which translates tasks to the printer language, appears here. The filter device depends on what kind of a printing configuration system is used, but its general functional principle remains unchanged: the document is received from the standard input, it is then sent to the standard output.

sh (suppress headers)

Because the server may be used for printing from several computers, pages with messages showing who owns the print task are usually printed before and after the document. This option switches these messages off, they are not needed on a home PC.

mx (maximum)

Limit of the maximum file size. If the parameter is set to zero, then there are no limitations. Example: mx#0

rp (remote printer)

Name of remote printer to which the documents will be sent.

rm (remote machine)

Name of machine (computer) on which this printer is installed.

Here is an example of the file /etc/printcap, configured for HP LaserJet printer, connected to the first parallel port of a computer:

printer||HP LaserJet 6L||lp:\      
    :sd=/var/spool/lpd/printer:\
    :lf=/var/log/lp-errs:\      
    :if=/usr/sbin/lpdomatic:\
    :af=/etc/foomatic/lpd/printer.lom:\      
    :lp=/dev/lp0:\
    :sh:\      
    :mx#0:

If you are printing to a remote printer, then the file may look the following way:

lp|dj|deskjet:\      
    :sd=/var/spool/lpd/dj:\
    :rm=machine.out.there.com:\      
    :if=/usr/bin/filter:\
    :rp=printername:\      
    :sh:

Fuller information about the meaning of configuration parameters can be obtained from man pages.

CUPS Spooler

Since the time of the early versions of lpd several attempts have been made to create something more flexible and convenient in its configuration. In ALT Linux 2.3, the powerful ultra-modern CUPS (Common Unix Printing System) is included aside from the classical (and thus simple and light) lpd. CUPS is gradually winning more and more fans and has by now practically become a new standard among spoolers.

Peculiarities of CUPS

CUPS has many new capabilities in comparison to older spoolers. Among those are:

A convenient configuration system

You should simply launch your favorite Web browser and open the network address http://localhost:631. You will then see an attractive interface allowing you to add a printer to the system or to delete it, to view queues for each printer individually, to re-launch already printed tasks, etc.

Remote printing is simple to setup

If your office already has a configured CUPS server, nothing else needs to be configured. All CUPS systems communicate with each other, and your server will know that another server with a configured printer already exists on the network. Thus it will direct its tasks to that server.

Support of the most advanced and secure protocols

IPP is the main protocol for server-client data exchange; printing through a protected SSL connection is also possible.

Support for multiple languages

The older lpd system could only print in one system language. CUPS can serve users who work with completely different encodings.

A unified system for storing printer descriptions in the so-called PPD files

A manufacturer can supply the relevant description together with the printer (but this still does not eliminate the need to have an appropriate driver in GS).

CUPS Configuration Files

Configuration files for CUPS are located in the /etc/cups directory, and their format is more user-friendly. The file /etc/cups/cupsd.conf contains the main parameters of the server with detailed descriptions for each of them. Here are some of the most frequently used parameters:

LogLevel

Level of logging detail. By default, it is set to info. If you are having problems with CUPS, and the log file does not have any useful information, the level of detail can be raised to maximum using the debug2 option.

Port

The TCP port that the server uses to await requests from clients. By default, it is 631 (this port address is reserved for the IPP protocol).

Location, Order, Allow, Deny

This is a series of directives analogous to those used in the Apache Web server configuration. Order refers to the order of evaluation of Allow and Deny values. Allow stands for addresses from which access is allowed, Deny for those, from which access is blocked. For example:

<Location />
Order Deny,Allow 
Deny From All 
Allow From 127.0.0.1
</Location>

This means that first the server will evaluate if access is denied from particular computers (in this case it is denied from all), and then if it is allowed from certain ones (in this case, it is allowed only from the server itself). The last parameter will be useful in setting up a single CUPS server for the entire LAN. Access rules can be as complicated as needed because the concept of classes is supported.

The file /etc/cups/client.conf contains client-side configuration options. Only two parameters are stored in it: server location and data encryption. Most likely, you will not need to change anything.

The file /etc/cups/printers.conf contains printer descriptions. The format of the file is rather intuitive and similar to XML syntax. Here is a sample of a local printer configuration stored in this file:

<DefaultPrinter printer>
DeviceURI parallel:/dev/lp0
State Idle 
Accepting Yes 
JobSheets none none 
QuotaPeriod 0
PageLimit 0 
KLimit 0 
</Printer>

Among these, Accepting (which shows if the printer accepts tasks) and DeviceURI (containing the special description of the printer location) are the most significant. The correct way to specify a URI will be described further, when we address the topic of foomatic.

Descriptions of each installed printer (in relevant PPD files) are stored in the /etc/cups/ppd/<printer_name>.ppd files. Every time the server starts, it checks if new printer (PPD file) descriptions have appeared in the /usr/share/cups/model directory and checks the serial and parallel ports of the computer. That is why it takes some time to start the server.

To send a job to a printer, the lpr command may be used, as if lpd were installed as a spooler. Likewise, to view the printer job queue, lpq may be used. To cancel a job, use the command cancel job_number.

CUPS Configuration

The knowledge you have by now should be sufficient to try and set up a printer manually. But there is no need to do this, as there are other, more convenient and visual methods.

Browser-Based CUPS Configuration

Launch your favorite Web browser and open the URL http://localhost:631 (for instance, lynx localhost:631). You will see the CUPS configuration interface. Choose the section “Manage Printers”, then the section “Add Printer”. Then you will be asked to enter username and password of the CUPS administrator, by default this is the system administrator (root).

When the first dialogue appears, it is sufficient to specify the printer name. Its description is auxiliary, and the location is only needed in the case when you have a complex system of CUPS access control set up.

In the next dialogue you should choose the device, to which the printer is connected.

Two subsequent dialogues are intended for choosing the printer model and manufacturer. Descriptions of models (PostScript Printer Description files, PPD) are stored in the /usr/share/cups/model directory. If you see suspiciously few models, install the cups-drivers package. Pay attention to the fact that this package conflicts with foomatic, a distinct configuration system, and so you should decide which method you want to use.

Finally, you may send a sample page to the printer.

Configuring CUPS with foomatic

It is difficult to give a concise description of what foomatic is. It is both a database of printer model descriptions and a configuration interface at the same time. Moreover, foomatic is capable of configuring practically all spoolers known to this day, CUPS being one of them.

The configuration procedure may be best examined in a specific example. Let us say we need to set up an HP LaserJet 1100 printer named SOMEPRINTER, connected to a Microsoft Windows computer named SOMEHOST that is a part of the SOMEGROUP workgroup.

  1. Let us form a URI describing the printer location. Its general format is the following: <protocol>://<location>. The location depends on the protocol.

    If the printer is connected locally, then the URI is file://path_to_file, particularly, a device file may be specified: (for instance, /dev/lp0).

    If the remote server is controlled by Microsoft Windows (our case), then the URI is smb://user:password@SOMEGROUP/SOMEHOST/SOMEPRINTER. Some fields in the description may not be mandatory.

    Finally, if we are dealing with a Netware server, the URI is ncp://user:password@SERVER/PRINTER.

  2. Let us now look at the available printer model descriptions. To do this, we can execute the command foomatic-configure -O | less. The description will be sent to the screen in the XML format. Let us find an appropriate description:

    <printer>  
    	<id>62816</id>
    	<make>HP</make>  
    	<model>LaserJet 1100</model>
    	<functionality>A</functionality>
    	<autodetect>    
    	<parallel>
    	<commandset>MLC,PCL,PJL</commandset>
    	<description>HP LaserJet 1100 Printer</description>
    	<manufacturer>Hewlett-Packard</manufacturer>
    	<model>HP LaserJet 1100</model>
    	</parallel>  
    	</autodetect>  
    	<drivers>
    	<driver>ljet4</driver>
    	<driver>stp</driver>
    	</drivers>
    	</printer>

    We are above all interested in the description identifier, marked by a pair of <id> tags - in our case, this is 62816. Let us also choose the ghostscript driver (choosing one driver or another is a matter of experience and taste). We will settle with ljet4, the main workhorse in this family of printers.

  3. Now we have gathered enough information to perform printer configuration. This is done with the foomatic-configure command. We will specify the desired spooler (parameter -s), printer name (parameter -n), description identifier, driver and URI.

    foomatic-configure -s cups -n Laser_Jet -p 62816 -d ljet4 -c \ smb://user:password@SOMEGROUP/SOMEHOST/SOMEPRINTER

Now everything is ready. Configuration settings may be viewed directly in the spooler configuration files, or using the command foomatic-configure -Q. On my computer, this command gives the following output:

<defaultqueue>printer</defaultqueue> 
    <queue foomatic="1" spooler="cups">
    <name>Laser_Jet</name>
    <printer>62816</printer>
    <driver>ljet4</driver>
    <connect>smb://user:password@SOMEGROUP/SOMEHOST/SOMEPRINTER</connect>
    <description>HP LaserJet 1100</description> 
    </queue>
    <queue foomatic="0" spooler="cups">  
    <name>lexmark</name>
    <connect>file:/dev/lp0</connect>
    </queue>
    <queue foomatic="1" spooler="cups">
    <name>printer</name>
    <printer>62368</printer>
    <driver>ljet4</driver>
    <connect>file:/dev/lp0</connect>
    </queue>
    </queues>

How To Remove Unneeded Printers?

If you got involved in printer configuration too deeply and are now confused by a dozen of printers you have installed, it is a good time to delete the ones you do not actually need.

Printers can be removed manually by deleting their descriptions from the spooler configuration files (/etc/cups/printers.conf). For CUPS, you may use the Web interface. If you have used foomatic (or printerdrake), it is useful to know the command:

      	$ foomatic-configure -s spooler_type -n printer_name -R
    

where spooler_type is CUPS.

Summary

Let us summarize the results. The printing system in Linux consists of three components:

  1. Setup interface (foomatic).

  2. Spooler (CUPS, lpd).

  3. Filter (ghostscript).

For high-quality printing from the gimp graphical editor, and for printing on jet printers in general, gimp-print package is useful. It consists of three components: a plugin for gimp, descriptions of printers in PPD format, and descriptions of printers in foomatic format. After installation of the package, the Print item will appear in gimp menu, and an opportunity to choose the new gimp-print driver during printing configuration will become available. You should definitely try this driver, in most cases it improves the quality of printing.

If you are using CUPS and do not wish to print through lpr, then its graphical analogue xpp is at your service. It allows to assign a large number of additional configuration parameters for the CUPS server.

What should be chosen, CUPS or lpd? This is a difficult question. If you are setting the printing system up using foomatic, it alleviates the differences between printing systems, and thus it is better to choose what suits your tasks best. If you can set up one spooler manually like a magician, but do not know how to set up the other one, choose the one that you know. CUPS has many useful functionalities and is irreplaceable in networks with large numbers of users. lpd, on the other hand, is lighter, easier to set up, simpler in structure, and, possibly, better suits a workstation with a locally connected printer.