A print filter definition tells the LP print service about the filter, what print filter program to run, what kind of conversion the print filter does, and so on. A set of filter descriptor files are provided in the /etc/lp/fd directory. These files describe the characteristics of the filters (for example, fast filter or slow filter), and point to the filter programs (for example, /usr/lib/lp/postscript/postdaisy).
When defining a new print filter, you must create a print filter definition.
A print filter definition contains the following information used by the LP print service:
Name of the filter program to run
Input types the filter program accepts
Output types the filter program produces
Printer types to which the filter program can send jobs
Names of specific printers to which the filter program can send jobs
Filter types (either fast or slow)
Options
You can type the characteristics as direct input to the lpfilter command. You also can create a file that specifies the filter's characteristics, and use the file name as input to the lpfilter command arguments. Such a file is called a filter descriptor file and should be located in the /etc/lp/fd directory. These files are not the filters themselves. Rather, these files point to the filters.
Whether you store the information in a file, or type the information directly on the command line, use 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 |
If you provide more than one definition (that is, more than one line) for any filter characteristic other than Options, only the second definition is used by the print service.
The information can be arranged in any order, and not all the information is required. When you do not specify values, the values shown in the following table are assigned by default. These values are not very useful, which is why you should specify values.
Table 8–1 Default Values for lpfilter Command
Item |
Default Value |
---|---|
Input types |
any |
Output type |
any |
Printer types |
any |
Printers |
any |
Filter type |
slow |
Use the full path of the filter program. If there are any fixed options that the program always needs, include them here.
Input types is a list of file content types that the print filter can process. The LP print service does limit the number of input types, but most filters can accept only one input type. Several file types can be similar enough, such that the filter can deal with them. You can use whatever names you prefer, with a maximum of 14 alphanumeric characters and dashes. Do not use underscores as part of the input type name.
The LP print service uses these names to match a filter to a file type, so 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. Inform your users of these names so that they know how to identify the file type when submitting a file for printing.
Output types is list of file types that the filter can produce as output. For each input type, the filter produces a single output type. The output type can vary, however, from job to job. The name of the output type is restricted to 14 alphanumeric characters and dashes.
The output type names should either match the types of available (local or remote) printers, or match the input types handled by other filters. The LP print service groups filters in a shell pipeline if it finds that several passes by different filters are needed to convert a file. You will unlikely need this level of sophistication, but the LP print service allows it. Try to find a set of filters that takes as input types all the different files the users might want printed, and that converts those files directly into file types the printer can handle.
Printer types is a list of the types of printers into which the print filter can convert files. For most printers and filters, you can leave this part of the filter definition blank, because this list is identical to the list of output types. However, this list can be different. For example, you could have a printer with a single printer type for purposes of initialization. However, that printer can recognize several different file content types. Essentially, this printer has an internal filter that converts the various file types into a filter type that it can handle. Thus, a filter might produce one of several output types that match the file types that the printer can handle. The print filter should be marked as working with that printer type.
As another example, you might have two different models of printers that are listed as accepting the same file types. Due to slight differences in manufacture, however, 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 printer 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 would list this filter as working only on type B printers.
A print filter normally can work with all printers that accept its output, so you can usually skip this part of the filter definition.
You might, however, have some printers that are inappropriate for the output that the filter produces. For example, you might want to dedicate one printer for fast turnaround, only sending files that require no filtering to that printer. Other printers of identical type can be used for files that need extensive filtering before they can be printed.
The LP print service recognizes fast filters and slow filters, as described in Types of Filters.
Slow filters that are invoked by printing modes, by using the lp -y command, must be run on the system from which the print request originated. The LP print service cannot pass values for modes to print servers. It can, however, match a file content type (specified after the -T option of the lp command) to a content type on a print server. Therefore, if you want to activate special modes on a print server, you must specify content types that permit the LP print service to match input types and output types.
Options specify how different types of information are converted into command-line arguments to the filter command. This information can include specifications from a user (with the print request), the printer definition, and the specifications implemented by any filters that are used to process the request.
There are 13 sources of information for defining print filter options, each of which is represented by a keyword. Each option is defined in a template. 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 filter characteristics
The options specified in a filter definition can include none, all, or any subset of the 13 keywords. In addition, a single keyword can be defined more than once, if multiple definitions are required for a complete filter definition. The following table contains descriptions of the 13 keywords available for defining options in a print filter definition.
Table 8–2 Keywords for Print Filter Options
Keyword |
Patterns |
Example |
|
---|---|---|---|
Content type (input) |
INPUT |
content-type |
troff |
Content type (output) |
OUTPUT |
content-type |
postscript, impress |
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 |
MODES |
mode |
landscape |
A print filter definition can include more than one template. Multiple templates are entered on a single line and separated with commas, or they are entered on separate lines, preceded by the Options: prefix.
The format of a template is as follows: keywordpattern = replacement
The keyword identifies the type of option being registered for a particular characteristic of the filter.
The pattern is a specific option for the keyword.
The replacement is what happens when the keyword has the noted value.
For an example of how an option is defined for a particular filter, suppose you want to have the print service scheduler assign print requests to filters following this criteria:
If the type of OUTPUT to be produced by the filter is impress, then pass the -I option to the filter.
If the type of OUTPUT to be produced by the filter is postscript, then pass the -P option to the filter.
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 defined as OUTPUT. In the first template, the 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 replacement is -P.
To determine which values to supply for each type of template (that is, for the pattern and replacement arguments for each keyword), consider the following:
The values for the INPUT templates come from the file content type that needs to be converted by the filter.
The values for the OUTPUT templates come from the output type that has to be produced by the filter.
The value for the TERM template is the printer type.
The value for the PRINTER template is the name of the printer that will print the final output.
The values for the CPI, LPI, LENGTH, and WIDTH templates come from the user's print request, the form being used, or the default values for the printer.
The value for the PAGES template is a list of pages that should be printed. Typically, the value consists of a list of page ranges separated by commas. Each page range consists of a pair of numbers separated by a dash, or a single number. (For example, 1–5,6,8,10 indicates pages 1 through 5, plus pages 6, 8, and 10.) However, whatever value was given in the -P option to a print request is passed unchanged.
The value for the CHARSET template is the name of the character set to be used.
The value for the FORM template is the name of the form requested by the lp -f command (the command used to submit a print request).
The value of the COPIES template is the number of copies of the file to print. If the filter uses this template, the LP print service reduces to one the number of copies of the filtered file it prints. This “single copy” includes the multiple copies that are produced by the filter.
The value of the MODES template comes from the lp -y command. Because a user can specify several -y options, the MODES template might have several values. The values are applied in the left-to-right order given by the user.
The replacement option shows how the value of a template should be given to the filter program. This part typically a literal option, sometimes with the placeholder asterisk (*) included to show where the value goes. The pattern and replacement options also can use the regular expression syntax of the ed command for more complex conversion of user input options into filter options. All regular expression syntax of ed is supported, including the \( ... \) and \n constructions. These constructions can be used to extract portions of the pattern option for copying into the replacement option, and the & option, which can be used to copy the entire pattern option into the replacement option. For more information, see the ed(1) man page.
If a comma or an equal sign (=) is included in a pattern or a replacement option, precede it with a backslash (\). A backslash in front of any of these characters is removed when the pattern or replacement option is used.