The CUPS filter interface provides a standard method for adding support for new document types or printers to CUPS.
Each filter is capable of converting from one or more input formats to another format that can either be printed directly or piped into another filter to get it to a printable format.
.LP
Filters \fBMUST\fR be capable of reading from a filename on the command-line or from the standard input, copying the standard input to a temporary file as required by the file format.
All output \fBMUST\fR be sent to the standard output.
Filters \fBMUST NOT\fR attempt to communicate directly with the printer, other processes, or other services.
.LP
The command name (\fIargv[0]\fR) is set to the name of the destination printer but is also available in the \fBPRINTER\fI environment variable.
.SHOPTIONS
Options are passed in \fIargv[5]\fR and are encoded from the corresponding IPP attributes used when the job was submitted. Use the
.BRcupsParseOptions()
function to load the options into a \fBcups_option_t\fR array and the
.BRcupsGetOption()
function to get the value of a specific attribute.
Be careful to look for common aliases of IPP attributes such as "landscape" for the IPP "orientation-requested" attribute.
.LP
Options passed on the command-line typically do not include the default choices the printer's PPD file. Use the
.BRppdMarkDefaults()
and
.BRcupsMarkOptions()
functions in the CUPS library to apply the options to the PPD defaults and map any IPP attributes to the corresponding PPD options.
Use
.BRppdFindMarkedChoice()
to get the user-selected choice for a PPD option. For example, a filter might use the following code to determine the current value of the \fBDuplex\fR PPD option:
.nf
ppd_file_t *ppd = ppdOpenFile(getenv("PPD"));
cups_option_t *options = NULL;
int num_options = cupsParseOptions(argv[5], 0, &options);
Sets the named job or printer attribute(s). The following job attributes can be set: "job-media-progress". The following printer attributes can be set:
Sets the "printer-state-message" attribute and adds the specified message to the current \fBErrorLog\fR using the "critical" log level.
.TP5
\fBDEBUG: \fImessage\fR
Adds the specified message to the current \fBErrorLog\fR using the "debug" log level.
\fBDEBUG\fR messages are never stored in the "printer-state-message" attribute.
.TP5
\fBDEBUG2: \fImessage\fR
.br
Adds the specified message to the current \fBErrorLog\fR using the "debug2" log level.
\fBDEBUG2\fR messages are never stored in the "printer-state-message" attribute.
.TP5
\fBEMERG: \fImessage\fR
Sets the "printer-state-message" attribute and adds the specified message to the current \fBErrorLog\fR using the "emergency" log level.
.TP5
\fBERROR:\fI message\fR
Sets the "printer-state-message" attribute and adds the specified message to the current \fBErrorLog\fR using the "error" log level.
.TP5
\fBINFO:\fI message\fR
Sets the "printer-state-message" attribute. If the current \fBLogLevel\fR is set to "debug2", also adds the specified message to the current \fBErrorLog\fR using the "info" log level.
.TP5
\fBNOTICE:\fI message\fR
Sets the "printer-state-message" attribute and adds the specified message to the current \fBErrorLog\fR using the "notice" log level.
.TP5
\fBPAGE:\fI page-number #-copies\fR
.TP5
\fBPAGE:\fI total #-pages\fR
Adds an entry to the current \fBPageLog\fR. The first form adds \fI#-copies\fR to the "job-media-sheets-completed" attribute. The second form sets the "job-media-sheets-completed" attribute to \fI#-pages\fR.
Sets the named keywords in the printer's PPD file. This is typically used to update default option keywords such as \fBDefaultPageSize\fR and the various installable options in the PPD file.
Sets, adds, or removes "printer-state-reason" keywords for the current queue. Typically this is used to indicate media, ink, and toner conditions on a printer.
.TP5
\fBWARNING:\fI message\fR
Sets the "printer-state-message" attribute and adds the specified message to the current \fBErrorLog\fR using the "warning" log level.
.SHENVIRONMENTVARIABLES
The following environment variables are defined by the CUPS
server when executing the filter:
.TP5
.BCHARSET
The default text character set, typically "utf-8".
.TP5
.BCLASS
When a job is submitted to a printer class, contains the name of the destination printer class. Otherwise this environment variable will not be set.
.TP5
.BCONTENT_TYPE
The MIME media type associated with the submitted job file, for example "application/postscript".
.TP5
.BCUPS_CACHEDIR
The directory where semi-persistent cache files can be found and stored.
.TP5
.BCUPS_DATADIR
The directory where data files can be found.
.TP5
.BCUPS_FILETYPE
The type of file being printed: "job-sheet" for a banner page and "document"
for a regular print file.
.TP5
.BCUPS_MAX_MESSAGE
The maximum size of a message sent to \fIstderr\fR, including any leading prefix and the trailing newline.
.TP5
.BCUPS_SERVERROOT
The root directory of the server.
.TP5
.BFINAL_CONTENT_TYPE
The MIME media type associated with the output destined for the printer, for example "application/vnd.cups-postscript".
.TP5
.BLANG
The default language locale (typically C or en).
.TP5
.BPATH
The standard execution path for external programs that may be run by the filter.
.TP5
.BPPD
The full pathname of the PostScript Printer Description (PPD) file for this printer.
.TP5
.BPRINTER
The name of the printer.
.TP5
.BRIP_CACHE
The recommended amount of memory to use for Raster Image Processors (RIPs).
.TP5
.BSOFTWARE
The name and version number of the server (typically CUPS/\fImajor.minor\fR).
.TP5
.BTZ
The timezone of the server.
.TP5
.BUSER
The user executing the filter, typically "lp" or "root"; consult the \fIcups-files.conf\fR file for the current setting.
.SHCONFORMINGTO
While the filter interface is compatible with System V interface scripts, CUPS does not support System V interface scripts.
.SHNOTES
CUPS printer drivers and backends are deprecated and will no longer be supported in a future feature release of CUPS.
Printers that do not support IPP can be supported using applications such as
.BRippeveprinter(1).
.LP
CUPS filters are not meant to be run directly by the user.
Aside from the legacy System V interface issues (\fIargv[0]\fR is the printer name), CUPS filters also expect specific environment variables and file descriptors, and typically run in a user session that (on macOS) has additional restrictions that affect how it runs.
Unless you are a developer and know what you are doing, please do not run filters directly.
Instead, use the
.BRcupsfilter(8)
program to use the appropriate filters to do the conversions you need.