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.
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.
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:
Determine if the program expects any files other than those submitted by a user for printing. If it does, those files must be in the directory of the person using the filter, or they must be readable by all users authorized to use the filter. The latter prerequisite is necessary because filters are run with the user ID and group ID of the user who submitted the print request.
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.
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.
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:
If there are any fixed options that the program always needs, include them here.
The print service does not impose a limit on the number of input types that can be accepted by a filter, but most filters can take only one. Several file types may be similar enough so that the filter can handle them. You can use any name having a maximum of 14 alphanumeric characters and dashes (not underscores). Because the print service uses these names to match a filter with a file type, follow a consistent naming convention. For example, if more than one filter can accept the same input type, use the same name for that input type when you specify it for each filter. Advise your users of the names so they know how to identify the type of a file when submitting that file for printing.
For each input type, the filter produces a single output type. The output type may vary, however, from job to job. The names of the output types are restricted to 14 alphanumeric characters and dashes.
These names should either match the types of printers you have on your system or match the input types handled by other filters. The print service groups filters together in a shell pipeline if it finds that several passes by different filters are needed to convert a file. Try to find a set of filters that take (as input types) all the different files your users may want printed and converts those files directly into types your printers can handle.
For most filters, this list is identical to the list of output types.
For example, you may have a printer that is given a single type for purposes of initialization, see Printer Types, but which can recognize several different types of files. In essence, this printer has an internal filter that converts the various types into one that it can handle. Thus, a filter may produce one of several output types that match the file types that the printer can handle. Label the filter as working with that printer type.
As another example, you may have two different models of printers that are listed as accepting the same types of files. However, due to slight differences in manufacture, one printer deviates in the results it produces. You label the printers as being of different printer types, say A and B, where B is the one that deviates. You create a filter that adjusts files to account for the deviation produced by printers of type B. Because this filter is needed only for those printer types, you list it as working only on type B printers.
For most printers and filters, you can leave this part of the filter definition blank.
For instance, you may want to dedicate one printer for fast turnaround. Only files that the printer can handle without filtering will be sent to that printer. Other printers, of identical type, you allow to be used for files that may need extensive filtering before they can be printed. In this case, label the filter as working with only the latter group of printers.
In most cases, a filter works with all printers that accept its output, so you can usually skip this part of the filter definition.
Fast filters are labeled fast because they incur little overhead in preparing a file for printing and because they must have access to the printer when they run. A filter that is to detect printer faults must be a fast filter. A filter that uses the PRINTER keyword as a filter option must be installed as a fast filter.
Slow filters are filters that incur a lot of overhead in preparing a file and do not require access to a printer. The print service runs slow filters in the background, without tying up a printer. This allows files that do not need slow filtering to move ahead. Printers will not be left idle while a slow filter works on a file if other files can be printed simultaneously.
Slow filters that are invoked by modes (using the -y option), must be run on the computer where the print request was issued. The print service cannot pass values for modes to server machines. It can, however, match a file content type (specified after the -T option of the lp command) to a content type on a server machine. Therefore, to activate special modes on a server machine, you must specify content types that will allow the print service to match input types and output types.
This information may include specifications from a user (with the print request), the printer definition, and the specifications implemented by any filters used to process the request.
There are 13 sources of information, each of which is represented by a keyword. Each option is defined in a template, which is a statement in the following format:
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."
The options specified in a filter definition may include none, all, or any subset of these 13 keywords. In addition, a single keyword may be defined more than once, if multiple definitions are required for a complete filter definition. See Defining Options With Templates.
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.
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.
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.
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:
lp -y expand report.dec10
the filter command will run with the following arguments:
/usr/bin/col -x -p -f
lp -T N37 -y expand report.dec10
the filter command will run with the following arguments:
/usr/bin/col -x
Qualifier: The default printer is not of type 450.
lp -y expand -T 450 report.dec10
the filter command will be run with the following arguments:
/usr/bin/col -b -x
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
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.)
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.
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
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
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.
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.
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.
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.
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.
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.