NEXT UP previous
Next: My Home Page

Printers

Most PC printers use a parallel port as a Centronics interface. In a DOS environment the printer ports are called LPT1 and LPT2. The equivalent device special files under Linux are:

	/dev/lp1
	/dev/lp2

Most systems will only have one printer installed, usually as /dev/lp1.

If you are used to using a printer in a DOS environment then you will be used to having direct and sole access to it. Remember, however, that Linux is a multi-user and multi-tasking operating system so that even though, in your particular case, you may be the only user, provision still needs to be made to operate a printer in an environment where several users may be making simultaneous requests to print.

The standard way to solve this problem is to use a print spooling program. With a print spooler in operation any print requests that are made are not routed directly to the printer but are sent to files in a spool directory instead. Then, a separate program can pick up the print jobs one at a time from the spool directory and send them to the printer.

Under Linux, the situation is slightly more complex than this simple scenario suggests. This is because, as well as printing to a local printer, it is also possible to print on remote printers over a network.

Print Services

The task of scanning the spool directories (there is one directory for each printer) and printing any waiting files is performed by a program called lpd. The lpd program is actually the line printer daemon which needs to be executed at system boot time, usually from within the startup file rc.M or rc.inet2.

The four standard commands to submit, remove, monitor and control print jobs are:

By default, all these commands operate on the printer called lp. If you want to specify an alternative printer you can use the -Pname command line switch, where name is the name of the printer to use. Or, you can set the PRINTER shell variable up with the printer name instead.

printcap

All that needs to be done now, is to see how the various print service configuration options are set up. This is all done in the file:

	/etc/printcap

This file is just a text file so you can use vi to modify it (if you login as root). The contents of the file are called printcap enties. Each printcap entry is just a set of configuration options - one printcap entry for each printer to which you will have access.

Two typical printcap entries are shown next, the first is for output to a local dumb dot matrix printer called lp. The second is for access to an HP 4L laser printer called hp, available over the network on a machine called gregory:

	lp|starsg10:\
		:lp=/dev/lpl:\
		:sd=/usr/spool/lp:\
		:lf=/usr/spool/lp/err-log:\
		:mx#0:\
		:sh:

	hp|hp41:\
		:lp=:\
		:rm=gregory:\
		:sd=/usr/spool/hp:\
		:lf=/usr/spool/hp/err-log:\
		:lf=/usr/local/bin/apsfilter:\ 
		:mx#0:

The first thing to notice is that printcap entries must only occupy a single logical line, with '\' characters used to signify that the the line is not yet complete.

The first field of each print cap entry starts at the beginning of a line and contains a list of names by which the printer may be known. The individual names are separated by '|' characters.

After the first field in each entry there follows a set of options and, where appropriate, their values.

Let us now work through the two printcap entries in turn, lp entry first. After the name field, the second line specifies the device special file to which the printer is attached (/dev/lp1 here). The third line specifies the spool directory for this printer as /usr/spool/lp. The fourth line gives the path to a log file which will be used to record any error messages generated while printing. The mx option specifies the maximum file size (in lKb blocks) that can be printed. A value of zero (as here) indicates that the size is unrestricted. The final option in this entry (sh) takes no parameters and just specifies that header page printing should be suppressed.

Now working through the hp entry, the second line is to specify the device special file for this printer. Notice, though, that because this printer is attached to a different machine this option specifies an empty parameter. The third line specifies the machine to which print requests for this printer should be sent (gregory in this example). The fourth line specifies a spool directory, which is still required even for a network printer to spool the files for printing before they are sent over the network. The fifth line specifies an error log file. The sixth line specifies a filter (apsfilter here) through which all documents will be passed on the way to the printer. These filter programs can be written to do anything to the text before it is printed. This particular filter will convert Postscript files into a form which can be printed on the HP 4L which is not a Postscript printer. This conversion is done by using the GNU Ghostscript program. The final line in this entry just specifies that the maximum file size for printing is unrestricted.

If a network printer is to be connected to your machine, then you must specify which remote machines will have permission to use the printer. The simplest way to do this is to enter a list of the machine host names for which permission is to be granted, into the file /etc/hosts.lpd.

There are very many more options which can be specified in a printcap entry than are shown here, though these examples will allow you to set up simple printer configurations. The print cap(S) manual entry contains a full list. Another document well worth reading on printer setup is the Printing-HOWTO document from the Linux Documentation Project.


NEXT UP previous
Next: My Home Page