The LP print service provides filter programs in the /usr/lib/lp/postscript directory. These filters cover most PostScript printing situations, where the destination printer requires the data to be in PostScript format. A print filter program must be a binary executable file.
There are two types of print filters: fast filters and slow filters.
Fast filters do not require much processing time to prepare a file for printing. They must have access to the printer when they run. To be capable of detecting printer faults, a print filter must be a fast filter. Any filter that uses the PRINTER keyword as a filter option must be installed as a fast filter.
Slow filters require a great deal of processing time to prepare a file for printing. They do not require access to the printer when they run. Slow filters are run in the background so they do not tie up the printer, allowing other files that do not need slow filtering to be printed.
The LP print service uses print filters to convert files from one content type to another content type. You can specify the accepted file content types for each printer. The user specifies the file content type when submitting a print request. Then, the LP print service finds a printer that can print files of that content type. Because many applications can generate files for various printers, this method is often sufficient. However, some applications can generate files that cannot be printed on any available printers.
Each time the LP print service receives a request to print a type of file that is in a format that cannot be accepted directly by a printer, the LP print service tries to match the content type of the print request with the content type of the available (or specified) printer. If there is a match, the file can be sent directly to the printer without filtering. If no match is found, or if the content type specifies that a filter be used, the LP print service tries to match the content type of the file with the input content type of available filters. In addition, the LP print service tries to match the output type of the filter with the content type of the printer. When an appropriate filter is found, the print request is passed through the filter.
A print filter handles special printing modes and requests to print specific pages. A special printing mode is needed to print any characteristics of print requests that require a customized filter.
Filters handle the following characteristics:
Pages to print
Number of copies
The LP print service provides default settings for these characteristics. However, a print filter can handle some characteristics more efficiently. For example, some printers can handle multiple copies more efficiently than the LP print service. So, in this case, you can provide a filter for multiple-copy page control.
Each printer has its own way of detecting printer faults and transmitting fault signals to the LP print service. The LP print service only checks for hang-ups (loss of carrier) and excessive delays in printing.
Some printers provide good fault coverage and can send a message that describes the reason for a fault. Other printers indicate a fault by using signals other than the signals for loss of carrier signal or shut off of data flow. A filter is required to interpret this additional printer fault information.
A filter can also put a print request on hold, wait for a printer fault to clear, and then resume printing. With this capability, the print request that was interrupted does not need to be reprinted in its entirety. Only a filter that knows the control sequences used by a printer can determine where to break a file into pages. Consequently, only such a filter can find the place in the file where printing should start after a fault is cleared.
When a print filter generates messages, those messages are handled by the LP print service. If alerts are enabled, the LP print service sends alerts to the system administrator. For further information, see Setting Up Printer Fault Alerts by Using LP Print Commands.
A print filter can be simple or complex, but it has to meet the following requirements:
The filter should get the contents of a file from its standard input and send the converted file to the standard output.
A program cannot be used as a filter if it references external files. You might be tempted to use a program such astroff, nroff, or a similar word processing program as a filter. The LP print service does not recognize references to other files, known as include files, from a filter program. Because troff and nroff programs allow include files, they can fail when used as filters. If the program needs other files to complete its processing. The program t should not be used as a filter.
The filter should not depend on files that normally would not be accessible to a user. If a filter fails when run directly by a user, it will fail when run by the LP print service.
A slow filter can send messages about errors in the file to standard error. a fast filter should not. Error messages from a slow filter are collected and sent to the user who submitted the print request.
If a slow filter dies because it received a signal, the print request is stopped and the user who submitted the request is notified. Likewise, if a slow filter exits with a nonzero exit code, the print request is stopped and the user is notified. The exit codes from fast filters are treated differently.
If you want the filter to detect printer faults, it should also meet the following requirements:
If possible, the filter should wait for a fault to be cleared before exiting. The filter should also continue to print at the top of the page where printing stopped after the fault is cleared. If you do not want use the continuation feature, the LP print service stops the filter before alerting the administrator.
The filter should send printer fault messages to its standard error as soon as the fault is recognized. The filter does not have to exit, but can wait for the fault to be cleared.
The filter should not send messages about errors in the file to standard error. These messages should be included in the standard output, where they can be read by the user.
The filter should exit with a zero exit code if the file is finished printing (even if errors in the file have prevented it from being printed correctly).
The filter should exit with a nonzero exit code, only if a printer fault has prevented the filter from finishing a print request.
When added to the filter table, the filter must be added as a fast filter.