[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Guide to Printers and Printing

Providing Filters

A filter is a program that you can use for the following purposes:

Not every filter can perform all three tasks. Given the printer-specific nature of these roles, the print service has been designed so that these roles can be implemented separately. This separation allows you or a printer manufacturer (or another source) to provide filters without having to change the print service.

A default filter is provided with the print service to provide simple printer fault detection. It does not convert files or handle any of the special modes. It may, however, be adequate for your needs.

You can use the print service to manage the use of filters as follows:

Note: Adding, changing, or removing filters can cause print requests that are still queued to be canceled. This is because the print service evaluates all print requests still queued to see which are affected by the filter change. Requests that are no longer printable, because a filter has been removed or changed, are canceled (with notifications sent to the users who submitted them). There can also be delays in the responses to new or changed print requests when filters are changed, due to the many characteristics that must be evaluated for each print request still queued. These delays can become noticeable if there is a large number of requests that need to be filtered.

Because of this possible impact, make alterations to filters during periods when the print service is idle.

Task 1: Converting Files

For each printer (local or remote), you can specify what file content types it can print. When a user submits a file to print on any printer and specifies its content type, the print service finds a printer that can handle files of that content type. Because many applications can generate files for various printers, this is often sufficient. However, some applications generate files that cannot be printed on your printers.

By defining and creating a filter that converts such files into a type that your printers can handle, you can support more applications in the print service. (The print service provides a few filters for converting various types of files into PostScript.) For each filter you add to the system, you must specify one or more types of input it can accept and the type of output it can produce (usually only one).

When a user specifies (by executing lp -T) a file content type that no printer can handle, the print service tries to find a filter that can convert the file into an acceptable type. If the file to be printed is passed through a filter, the print service then matches the output type of that filter with a printer type or the input type of another filter. The print service continues to match output types to input types in this way, thus passing a file through a series of filters, until the file reaches a printer that accepts it.

Example: HP DeskJet 500

In this example, the user Chris has run a spreadsheet program and has generated a file containing a copy of a spreadsheet. Chris now wants to print this file using the print service. You have only HP DeskJet 500 printers on your system. Fortunately, the spreadsheet application understands how to generate output for several printers, and Chris knows it is necessary to request output that can be handled by the HP DeskJet 500. When Chris submits the file for printing, the print service queues it for one of the printers; no filter is needed.

Example: Tektronix 4014 Output

In this example, the user Marty created a graphic image that can be displayed on a Tektronix 4014 terminal. Marty now wants to print this image, but all of the printers are PostScript printers. Fortunately, your system provides a filter called posttek that converts Tektronix type files to PostScript. Because you set the printer type to PostScript, the print service recognizes that it can use the posttek filter to convert Marty's output before printing it.

Task 2: Handling Special Modes

Filters can handle special printing modes. Each filter you add to the filter table can be registered to handle special modes and other aspects of printing, such as:

A filter is required to handle the special modes and printing of specific pages; the print service provides a default handling for the rest. However, it may be more efficient to have a filter handle some of the rest, or it is possible that a filter has to know several of these aspects to fulfill its other roles properly. A filter may need to know, for example, the page size and the print spacing if it is going to break up the pages in a file to fit on printed pages. As another example, some printers can handle multiple copies more efficiently than the print service, so a filter that can control the printer can use the information about the number of copies to skip the print service default handling of multiple copies.

Task 3: Detecting Printer Faults

Just as converting a file and handling special printing modes is a printer-specific role, so is detecting printer faults. The print service attempts to detect faults in general, and for most printers it can do so correctly. The range of faults that the print service can detect by itself, however, is limited. It can check for hang-ups (loss of carrier, the signal that indicates the printer is online) and excessive delays in printing (receipt of an XOFF flow-control character to shut off the data flow, with no matching XON to turn the flow back on). However, the print service cannot determine the cause of a fault, so it cannot inform you what to look for.

A well-designed filter can provide better fault coverage. Some printers are able to send a message to the host describing the reason for a fault. Others indicate a fault by using signals other than the dropping of a carrier or the shutting off of data flow. A filter can serve you by detecting more faults and providing more information about them than you would otherwise receive.

A filter can wait for a printer fault to clear and then resume printing. This service allows for more efficient printing when a fault occurs because the print request that was interrupted does not have to be reprinted in its entirety. Only a real filter, which has knowledge of the control sequences used by a printer, can know where a file breaks into pages. Thus only such a filter can find the place in the file where printing should resume.

The print service has a simple interface that allows a filter to send you fault information and to restart printing if it can. The alerting mechanism, Setting Up Printer Fault Alerts, is handled by the print service; the interface program that manages the filter takes all error messages from the filter and places them in an alert message that can be sent to you. If you have set the printer configuration so that printing should automatically resume after a fault is cleared, the interface program keeps the filter active, so that printing can pick up where it left off.

What Programs Make a Good Filter

It is tempting to use a program such as troff, nroff, or a similar word-processing program as a filter. However, the troff and nroff programs have a feature that allows references to be made in a source file to other files, known as include files. The print service does not recognize include files; it will not enqueue any that are referenced by a source file when that file is in a queue to be printed. As a result, the troff or nroff program, unable to access the include files, may fail. Other programs may have similar features that limit their use as filters.

Here are a few guidelines for evaluating a program for use as a filter:

Referenced files that are always specified by full pathnames may be acceptable, but only if the filter is used for local print requests. When used on requests submitted from a remote machine for printing on your machine, the filter may still fail if the referenced files exist only on the remote machine.

Defining a Filter

When adding a new filter, you must define the characteristics of its use. To do this, issue the lpfilter command with arguments that specify the values of the following filter characteristics:

See Adding a Filter to the Print Service for more information.

Filter definitions, which can be stored in a file or entered directly on the command line, have the following format:

   Command: command-pathname [options]
   Input types: input-type-list
   Output types: output-type-list
   Printer types: printer-type-list
   Printers: printer-list
   Filter type: fast or slow
   Options: template-list

The information can appear in any order. Not all the information must be provided. When you do not specify values for the items listed below, default values are assigned.

lpfilter Arguments

Item Default
Command: (no default)
Input types: any
Output types: any
Printer types: any
Printers: any
Filter type: slow
Options: (no default)

Default values define a flexible filter, so at minimum you must supply the input and output type(s). When you enter a list, you can separate the items in it with blanks or commas, unless it is a template-list. Items in a template-list must be separated by commas.

Each of these characteristics is described as follows:

When you have gathered enough information to define the characteristics of your filter, you are ready to run the lpfilter command, using your data as arguments. Because there are so many arguments and because some of them may need to be entered more than once (with different values), record this information first in a separate file and edit it, if necessary. You can then use the file as input to the lpfilter command and avoid typing each piece of information separately.

Defining Options With Templates

A template is a statement in a filter definition that defines an option to be passed to the filter command based on the value of one of the characteristics of the filter. A filter definition may include more than one template. Multiple templates may be entered on a single line and separated with commas, or they may be entered on separate lines, preceded by the Options: prefix.

The format of a template is as follows:

   keyword pattern=replacement

This type of statement is interpreted by the print service to mean: "When the information referred to by keyword has the value matched by pattern, take the replacement string, replace any asterisks it contains with the pattern specified or expand any regular expressions it contains, and append the result to the command line."

As an example, suppose you want to have the print service scheduler assign print requests to filters on the basis of the following criteria:

To specify these criteria, provide the following templates as options to the lpfilter command:

   Options: OUTPUT impress=-I, OUTPUT postscript=-P

If the Options: line becomes too long, put each template on a separate line, as follows:

   "Options: OUTPUT impress=-I"
   "Options: OUTPUT postscript=-P"

In both templates, the keyword is OUTPUT. In the first template, the value of pattern is impress and the value of the replacement is -I. In the second template, the value of pattern is postscript and the value of the replacement is -P.

Keyword Definitions and Examples

The following 13 keywords are available for defining Options in a filter definition:

Characteristic keyword Possible patterns Example
Content type (input) INPUT content-type troff
Content type (output) OUTPUT content-type postscript
Printer type TERM printer-type att495
Printer name PRINTER printer-name lp1
Character pitch CPI scaled-decimal 10
Line pitch LPI scaled-decimal 6
Page length LENGTH scaled-decimal 66
Page width WIDTH scaled-decimal 80
Pages to print PAGES page-list 1-5,13-20
Character set CHARSET character-set finnish
Form name FORM form-name invoice2
Number of copies COPIES integer 3
Special modes MODES mode landscape

To find out which values to supply for each type of template (that is, for the pattern and replacement arguments for each keyword), consider the following:

The replacement part of a template shows how the value of a template is given to the filter program. It is typically a literal option, sometimes with the place-holder * (asterisk) included to show where the value goes. The pattern and replacement can also use the regular expression syntax of the ed command for more complex conversion of user input options into filter options. All of the regular expression syntax of the ed command is supported, including the \( . . . \) and \n constructions, which can be used to extract portions of the pattern for copying into the replacement, and the &, which can be used to copy the entire pattern into the replacement.

Note:  If a comma or an equal sign (=) is included in a pattern or a replacement, escape its special meaning by preceding it with a backslash (\). Note that some regular expressions include commas that will have to be escaped this way. A backslash in front of any of these characters is removed when the pattern or replacement is used.

The following examples show how this works.

Example: col Filter

Suppose you already added a filter called col with the following definition:

   Input types:     N37, Nlp, simple
   Output types:    simple
   Command:         /usr/bin/col
   Options:         TERM 450 = -b, MODES expand = -x
   Options:         INPUT simple = -p -f

Note:  If you provide more than one definition (that is, more than one line) for any filter characteristic other than Options, only the last definition will be used by the print service.

After you have registered this definition with the print service by entering it as input with the lpfilter command, users' print requests will be handled as follows:

Example: dpost Filter

The filter program is called /usr/lib/lp/postscript/dpost. It takes one input type, troff, produces an output type called postscript and works with any printer of type PS (for PostScript). You have decided that your users need give just the abbreviations port and land when they ask for the paper orientation to be portrait mode and landscape mode, respectively. Because these options are not intrinsic to the print service, users must specify them using the -y option to the lp command.

The filter definition would look like this:

   Input types: troff
   Output types: postscript
   Printer types: PS
   Filter type: slow
   Command: /usr/lib/lp/postscript/dpost
   Options: LENGTH * = -l*
   Options: MODES portrait = -op, MODES land = -ol

A user submitting a file of type troff for printing on a PostScript printer (type PS), with requests for landscape orientation and a page length of 60 lines, would enter the following command:

lp -T troff -o length=60 -y land -d any

This filter would be invoked by the print service to convert the file as follows:

/usr/lib/lp/postscript/dpost -l60 -ol -pl

Example: Option Template

You add the following option template to the previous example:

Options:  MODES group\=\([1-9]\) = -n\l

This template is used to convert a MODES option of the form -y group=number into filter options -nnumber.

So if a user gives the command lp -y group=4, the dpost command would include the option -n4.

For additional examples, run the command

/usr/sbin/lpfilter -f filter -l

where filter is the name of the factory-installed PostScript filters. (For a list of PostScript filters, see PostScript Printers.)

Adding a Filter to the Print Service

To add the filter to the system after it has been defined, use one of the following commands:

   /usr/sbin/lpfilter -f filter-name -F filename
   /usr/sbin/lpfilter -f filter-name -

The first command gets the filter definition from a file, and the second command gets the filter definition from the standard input. A filter-name can be any string you choose, with a maximum of 14 alphanumeric characters and underscores.

If you need to change a filter, reenter one of the same commands. You need only provide information for those items that must be changed. Items for which you do not specify new information remain the same.

Removing a Filter

The print service imposes no fixed limit on the number of filters you can define. Remove filters that are no longer applicable to avoid extra processing by the print service, which must examine all filters to find one that works in a given situation.

To remove a filter, run the following command:

/usr/sbin/lpfilter -f filter-name -x

Examining a Filter

After you have added a filter definition to the print service, you can examine it by running the lpfilter command. The output of this command is the filter definition displayed in a format that makes it suitable as input. You may want to save this output in a file that you can use later to redefine the filter if you inadvertently remove the filter from the print service.

To present the definition of the filter on your screen, type the following command:

/usr/sbin/lpfilter -f filter-name -l

To capture the definition of the filter in a file for future reference, type the following command:

/usr/sbin/lpfilter -f filter-name -l > filename

Restoring Factory Defaults

The software is shipped from the factory with a default set of filters. As you add, change, or delete filters, you might overwrite or remove some of these original filters.

To restore some or all of the default set of filters to their original form after having changed them, type this command:

/usr/sbin/lpfilter -f filter-name -i

Replace filter-name with the name of the filter to restore or the word all to restore all the default filters.

Printer Types

The printer-type attribute is defined with the -T printer-type option of the lpadmin command. A printer type is the generic name for a printer. Typically it is derived from the manufacturer name. For example, the ACME\ Computer 356 Dot Matrix Printer might have the type 356. Assigning a type for each printer is important because the print software extracts information about printers from the terminfo database on the basis of type. This information includes a list of the printer capabilities that checks the configuration information you supply to the print service. (By checking the information you provide against the known capabilities of the type of printer you are configuring, the print service can catch inappropriate information you may have supplied.) The terminfo database also specifies the control data needed to initialize a particular printer before printing a file.

While you are not required to specify a printer type, it is good practice to do so. You enhance your system's ability to serve your users by classifying, on the basis of type, the printers available through the print service.

If you give a list of printer types, separate the names with commas. If you do not define a printer type, the default unknown is used.

You can assign several types to a printer if your printer is capable of emulating more than one kind of printer. For example, if your printer can emulate an IBM Proprinter XL, an Epson FX86e, and an HP LaserJet II, the terminfo database names these types 593ibm, 593eps, and 593hp, respectively. If you specify more than one printer type, the print service uses one of them, as appropriate, for each print request.

The following example shows how to use the lpadmin command to associate the type 593ibm with the printer named laser.

   /usr/sbin/lpadmin -p laser -T 593ibm

Note:  If you specify more than one printer type, you must specify simple as the content type.

Content Types

The content-type attribute is defined with the -I content-type-list option of the lpadmin command. Most printers can print files of two types: the same type as the printer type (if the printer type is defined) and the type simple (meaning an ASCII file), which is the default content type for all printers.

Files of content type simple are assumed to contain only two types of characters, printable ASCII characters and the following control characters:

backspace Moves the carriage back one space, except at the beginning of a line
tab Moves the carriage to the next tab stop; by default, stops are spaced every 8 columns on most printers
linefeed Moves the carriage to the beginning of the next line (may require special port settings for some printers--see Setting Printer Port Characteristics
form feed Moves the carriage to the beginning of the next page
carriage return Moves the carriage to the beginning of the same line (may fail on some printers)

The word carriage may be archaic for modern laser printers, but these printers perform actions similar to those done by a carriage. If a printer can handle several types of files, including simple, you must include simple explicitly in the content type list. If you do not want a printer to accept files of type simple, specify a blank content-type-list (-I "") on the lpadmin command line. Some printers, though, can accept (and print correctly) several different types of files. When adding this kind of printer, specify the names of the content types that the new printer accepts by adding these names to the list. (By default, the list contains only one type: simple.) If you are adding a remote printer, list the content types that have been established for it by the administrator of the system on which it resides.

The content-type-list is a list of names separated by commas or spaces. If you use spaces to separate the names, enclose the entire list (except for the -I) in quotes.

Common Types

Content type names might look like printer type names, but you are free to choose names that are meaningful to you and the people using the printer. The names must contain no more than 14 characters and may include only letters, digits, and underscores. The following table lists and describes some accepted content types.

Note: The names simple and any are recognized as having particular meanings by the print service; be sure to use them consistently. The name terminfo is also reserved, as a reference to all types of printers.

Commonly Used Content Types Table

Types Description
cif Output of BSD cifpbt
daisy Print files intended for a Diablo 630 (daisy-wheel) printer
dmd Print the contents of a bit-mapped display from a terminal
fortran ASA carriage control format
otroff CAT typesetter instructions generated by BSD or pre-System V troff (old troff)
pcl HP LaserJet native output format
plot Plotting instructions for Tektronix displays and devices
postscript PostScript language
raster Raster bitmap format for Varian raster devices
simple ASCII file
tek4014 Print files formatted for a Tektronix 4014 device
tex DVI format files
troff Device-independent output from troff

When a file is submitted to the print service for printing with the printer specified by the -d any option of the lp command, the print service searches for a printer capable of handling the job. The print service can identify an appropriate printer through either the content type name or the printer type name. Therefore, you may specify either name (or no name) when submitting a file for printing. If the same content type is printable by several different types of printers, use the same content type names when you add those printers. This makes it easier for the people using the printers because they can use the same name to identify the type of file they want printed, regardless of the printing destination.

Most manufacturers produce printers that accept simple ASCII files. While these printers are different types (and thus have different initialization control sequences), they may all be capable of handling the same type of file, which we call simple. Several manufacturers may produce printers that accept ANSI X3.64 defined escape sequences. However, the printers may not support all the ANSI capabilities; they may support different sets of capabilities. You may want to differentiate them by assigning different content type names for these printers.

Default Content Type

While it may be desirable to list content types for each printer, it is not always necessary. If you do not, the printer type is used as the name of the content type the printer can handle. If you have not specified a printer type, the print service assumes the printer can print only files of content type simple. This may be sufficient if you require users to specify the correct printer explicitly and if files are correctly prepared for the printer before being submitted for printing.

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]