|Title: ||Using a printer filter script with CUPS|
|Author: ||Roland Genske <email@example.com>|
My application relies on BSD-style printer filter scripts which I used
with LPRng. The Linux distribution I installed does not include LPRng
anymore. How can I make my filter scripts work?
Recent Linux distributions do not provide the LPR or LPRng printer spooler
anymore. Instead, the new CUPS (Common Unix Printing System) is installed.
A CUPS printer can be setup in two different ways:
using a PPD (PostScript Printer Definition) file
This is the standard method used by the CUPS GUI frontends, e.g. the KDE
using a System V style interface script
This is meant for "legacy printers", it provides a method to use a filter
script. This filter mechanism is compatible to HP-UX (System V style
To setup a printer using a System V style interface script, the lpadmin
command must be used:
lpadmin -p PRINTERNAME -v DEVICE -i SCRIPTFILE
- the name of the printer (i.e. the spooler queue) to create
- a CUPS device URL to specify where the data should be sent
- the filter script you want to install
lpadmin will copy your script file to the CUPS interface directory which is
commonly /etc/cups/interfaces. It is possible to edit an installed script
As an example, I suggest to create a text file with the following content
just to provide a starting point. The following script simply passes through
any data it receives from the spooler:
# Command line arguments
# Pass through
The device URI specifies where the data should be sent. There are a lot of
options, for example:
- Print to the first parallel port:
- Print to a HP JetDirect printer:
- Print to an already defined CUPS printer on this machine:
- Print to a Windows or Samba printer:
- Print to a remote LPD printer:
Please refer to the CUPS Software Administrators Manual for more details
about CUPS device URIs.
To continue my example above, I assume that a local CUPS printer named
"lj4050" is already defined (through the kprinter GUI). I will now create
an additional printer named "lj4050_2" using the lpadmin command:
lpadmin -p lj4050_2 -v ipp://localhost/printers/lj4050 -i script.txt
Note that "script.txt" is the example script file shown above. This
script is copied by lpadmin to the /etc/cups/interfaces directory,
renamed to "lj4050_2" and provided with the required permissions.
The new printer can now be used, it should behave as a "raw" printer.
Now the remaining step would be to edit the /etc/cups/interfaces/lj4050_2
script to implement the required filter functionality. The difference
between your existing BSD-style script and the new System V style script
is most likely how the data is passed to the script. With BSD it is
passed through the standard input, with System V the name of the file
containing the data is passed in argument 6.