.
contact contact

Using a printer filter script with CUPS

 
.
 

Title: Using a printer filter script with CUPS
Document: 1123683643
Author: Roland Genske <rhg@marxmeier.com>
Keywords: linux,printer,cups,lpr,lprng,filter,hp-filter


Q: 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?

Q: 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:

  1. using a PPD (PostScript Printer Definition) file

    This is the standard method used by the CUPS GUI frontends, e.g. the KDE kprinter utility.

  2. 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 interface script).

To setup a printer using a System V style interface script, the lpadmin command must be used:

 lpadmin -p PRINTERNAME -v DEVICE -i SCRIPTFILE
PRINTERNAME
the name of the printer (i.e. the spooler queue) to create

DEVICE
a CUPS device URL to specify where the data should be sent

SCRIPTFILE
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 file afterwards.

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:

#! /bin/sh

# Command line arguments
job="$1"
user="$2"
title="$3"
numcopies="$4"
options="$5"
filename="$6"

# Pass through
cat "$filename"

The device URI specifies where the data should be sent. There are a lot of options, for example:

  • Print to the first parallel port:
     parallel:/dev/lp1
    

  • Print to a HP JetDirect printer:
     socket:/192.168.66.77:9100
    

  • Print to an already defined CUPS printer on this machine:
     ipp:/localhost/printers/lj4050
    

  • Print to a Windows or Samba printer:
     smb:/192.168.66.88/lj4050
    

  • Print to a remote LPD printer:
     lpd:/192.168.66.99/lj4050
    

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.

For example:

  • If your script contains a line like
     cat -
    
    to pass the data to the printer, it should be replaced with:
     cat "$filename"
    

  • If your script contains a line like
     recode iso88591..roman8
    
    to recode the data on the fly, it should be replaced with:
     recode iso88591..roman8 < "$filename"
    

 
 
.
 
 
  Privacy | Webmaster | Terms of use | Impressum Revision:  Wed Aug 10 16:20:43 2005  
  Copyright © 1995-2004 Marxmeier Software AG