User Tools

Site Tools


CUPS Printing Setup on Debian Etch


Apache2 should first be installed to use the CUPS web interface at

Adding a Printer


lpadmin -p "Printername" -v backend-driver -D "Printer description" -P ppdfile.ppd

If no -P option is given, a raw printer is assumed. Issuing the -P option copies the specified file to the /etc/cups/ppd directory, and renames it to Printername.ppd. A printer can be switched between text and raw by removing the corresponding ppd file from the /etc/cups/ppd directory and reloading CUPS. Note that Printername must not have any embedded spaces.

Enable the printer with

cupsenable Printername
cupsaccept Printername

Printers can also be added via the web interface.

Parallel Printers

In Debian Etch, the lp module is not installed by default. Add the line


to /etc/modules

Serial Printers

First copy the serial backend to the backend directory:

cp /usr/lib/cups/backend-available/serial /usr/lib/cups/backend

Ensure that the serial port is accessible by the lp group:

chown root.lp /dev/ttyS0

Add the printer with serial parameters. e.g.

lpadmin -p DEC-LA100 -v serial:/dev/ttyS0?baud=9600+size=8+parity=none+flow=hard

CUPS Backends

Additional CUPS backends can be written and placed in the /usr/lib/cups/backend directory. See man backend.

ASCII Printers and CUPS Filters

Simple ASCII printers can be set up as raw printers, but a better way is to set up as a “Generic text only” printer. The difference is that the generic text only printer allows a CUPS filter to be specified, which is useful for doing such things as page counting, LF → CR/LF expansion, or Form Feed stripping. The Ubuntu cupsys package includes the two files necessary for this: textonly (shell script) and textonly.ppd. The textonly script should be placed in /usr/lib/cups/filter (755, root.root), and textonly.ppd copied into /etc/cups/ppd (and renamed to Printername.ppd accordingly).

The key line in textonly.ppd is:

*cupsFilter: "text/plain 0 textonly"

where textonly is the filter to execute.

Formfeed Stripping

Old problem - Windows Generic Text printer driver printing only dot-matrix labels, using Access, inserts FF after each label. To fix, ensure Windows Printing Preferences is set to either Cut Sheet or Cont Feed - With Break. This ensures Formfeeds are actually sent out (if Cont Feed - No Break is selected, Windows driver sends out LF's instead). Then create a new filter textonly-stripff with the line:

# Strip FF's and translate LF->CRLF.
sed -e 's/\f//g;s/$/'`echo -ne '\r'`'/g' "$TMPFILE2"

and change PPD line to

*cupsFilter: "text/plain 0 textonly-stripff"

Using the CUPS Windows Postscript Driver

Adding the Driver

Using Samba, the CUPS Windows Postscript driver allows for “easy” downloading of a single postscript driver to Windows machines from the Samba CUPS-enabled server, irrespective of the actual printer.

Obtain the tarball from the CUPS website, extract and build. libcupsys2-dev is needed for the make install, smbclient is needed by cupsaddsmb, so:

aptitude install libcupsys2-dev smbclient
cd /tmp
tar zxf cups-windows-6.0-source.tar.gz
cd  cups-windows-6.0
make install

Copy the following files from a Windows system to /usr/share/cups/drivers:


Note, file names must be lower case - see man cupsaddsmb for more details.

Now run with

cupsaddsmb -H cupsserver -U root -v Printername

If the above gives an NT_STATUS_LOGON_FAILURE, check that the roor password is actually set with

pdbedit -Lw

If not, add with

smbpasswd root

Note that a “correct” PPD file for the printer must be present in /etc/cups/ppd, otherwise cupsaddsmb will refuse to complete. PPD's can be checked at

Samba Configuration

Edit /etc/samba/smb.conf to include the following lines:

Under [global]:

   load printers = yes
   printing = cups
   printcap name = cups
   print command =
   lpq command = %p
   lprm command =
   comment = All Printers
   path = /var/spool/samba
   browseable = no
   public = yes
   guest ok = yes
   writable = no
   printable = yes
   printer admin = root
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   guest ok = no
   read only = no
   write list = root

For printers which do not require the Postscript drivers (for example if using Windows client drivers, or Generic Text printers), these must be specified - e.g.

# These printers require client drivers (actually just generic ASCII).
# They override the catch-all [printers] for specific entries.
# Note must be browseable (which is the default).
   path = /var/spool/samba
   public = yes
   guest ok = yes
   writable = no
   printable = yes
   printer admin = root
   use client driver = yes

Note comment that such printers need to be browseable, whereas this is specifically switched off in the [printers] section.

Putting It All Together


Sambafax uses Hylafax to send a document to a recipient, based on a fax number embedded in a Postscript document. Sambafax was originally written by Ignace Suy. The modified version below works under CUPS, using the CUPS Postscript drivers described above. It also uses pstotext, which does a better job of extracting the fax number from the Postscript file, as well as handling fax numbers which may be split over a number of lines.

# Faxing with HylaFax through a faxprinter
# Heavily modified from original version. Supports CUPS and LPR
# $Id: sambafax,v 1.9 2009-06-30 08:43:41 tda Exp $

# Printer spool type (LPR or CUPS)

# Constants

# Make up a temporary file using PID

# Fax number format
# Match FAX : '01234 567890'
# Deals with newlines in string and 0xad as hyphen
b testfirst
: appendnext
y/FAX\n\xad\xa3/fax - /
: testfirst
s/.*fax *: *'\([0-9 ][0-9 ,-]*[0-9 ]\)'.*/\1/
T appendnext
s/[ -]//g

# Retrieve the username and hostname from the parameters
if [ $PRINTSYSTEM = "LPR" ]; then
  while :
    case "$1" in
        -n) Username="$2"
            shift ; shift
        -h) Hostname="$2"
            shift ; shift
        -*) shift
         *) break
  cat >${FAXFILE}
  cat "$6" >${FAXFILE}

# If the samba user is anonymous then send mails to the postmaster
if [ "${Username}" = "nobody" ]; then

# Retrieve the faxnumber from the printfile
FAXNUM=`pstotext ${FAXFILE} | sed -n "${PARSE}"`

# If faxnumber is found fax the tempfile
# We do not check the validity of the faxnumber, let sendfax do this...
if [ "${FAXNUM}" = "" ]; then
  (echo "To: ${MailTo}"
   echo "From: The HylaFAX Samba print service <fax>"
   echo "Subject: Your facsimile request failed"
   echo ""                                                                 
   echo -n "The faxnumber is not recognized in your fax of " 
   echo -n `date`
   echo "."
   echo "The faxnumber is recognised by this text:"
   echo ""                                                                 
   echo "   Fax: 'd,ddd-dd ddddd'"
   echo ""                                                                 
   echo "Only spaces, ',' or '-' characters are allowed between the digits."
   echo ""
   echo "Please correct and retry."
  ) | 2>&1 $SENDMAIL -ffax -oi ${MailTo}
  sendfax -n -D -m -f ${MailTo} -d ${FAXNUM} ${FAXFILE}

# Remove the temp file
# rm -f ${FAXFILE}

# End of file

First, copy the sambafax script to /usr/lib/cups/backend, then

lpadmin -p "Faxprinter" -v sambafax -D "Fax printer" -P sambafax.ppd

sambafax.ppd is any “correct” PPD file, to allow cupsaddsmb to complete (the resultant PPD is then deleted, as Faxprinter needs to be a raw printer).

cupsaddsmb -H cupsserver -U root -v Faxprinter
rm /etc/cups/ppd/Faxprinter.ppd

DEC Letterprinter LA100

This is an ASCII printer on a serial port; add with:

lpadmin -p DEC-LA100 -v serial:/dev/ttyS0?baud=9600+size=8+parity=none+flow=hard -D "DEC Letterprinter 100" -P textonly.ppd

To /etc/samba/smb.conf, add section:

   path = /var/spool/samba
   public = yes
   guest ok = yes
   writable = no
   printable = yes
   printer admin = root
   use client driver = yes

NEC P2 Plus

This is an ASCII printer on a parallel port; add with:

lpadmin -p NEC-P2 -v parallel:/dev/lp1 -D "NEC Pinwriter P2 Plus" -P textonly.ppd

Then edit /etc/cups/ppd/NEC-P2.ppd:

*cupsFilter: "text/plain 0 textonly-stripff"

to remove Formfeeds.

To /etc/samba/smb.conf, add section:

   path = /var/spool/samba
   public = yes
   guest ok = yes
   writable = no
   printable = yes
   printer admin = root
   use client driver = yes

OKI C5450

This is a Postscript network printer; add with:

lpadmin -p OKI-C5450 -v lpd://c5450/lpt1 -D "Colour printer" -P OKI-C5450.ppd
cupsaddsmb -H cupsserver -U root -v OKI-C5450

Printing to a Remote Machine

Server is machine with printer. Client is machine from which to print.

On server, ensure that /etc/cups/cupsd.conf included the following lines:

Browsing On
BrowseOrder allow,deny
BrowseAllow @LOCAL

If access is required from a different network, add another BrowseAllow line - e.g.

BrowseAllow 192.168.2.

Under the <Location/> section, and the <Location /admin> section, add similar lines

Allow 192.168.2.

if accessing from a different net.

On the client, ensure a BrowsePoll line is present:

Browsing On
BrowseOrder allow,deny
BrowseAllow @LOCAL

Printing Text Files

Print options can be specified on the lpr command line. e.g.

lpr -pLaserjet-6P -o cpi=11.5 -o lpi=6 -o page-top=33 [file]

Alternatively, printer options can be set by the lpoptions command:

lpoptions -pLaserjet-6P -o cpi=11.5 -o lpi=6 -o page-top=33

Printer Instances

Multiple options set can be set up using printer “instances”, where each instance of a single printer can have a different set of options.

To set a printer instance, use:

lpoptions -pLaserjet-6P/instance1 -o cpi=11.5 -o lpi=6 -o page-top=33

To delete an instance:

lpoptions -xLaserjet-6P/instance1

Printer instances set by root are global.

Note that printer instances are not presented on the CUPS web interface.

Printing Text Files From Windows Command Line

There are a number of obstacles to printing with specific option sets through Samba with CUPS:

  1. Samba appears to not support printer instances via the CUPS API. They simply do not appear as listed printers. Furthermore, attempts to specifically list a printer instance also do not work.
  2. Any printer options set with lpoptions (see above) are ignored.
  3. It may be possible to define a special printer, printing = sysv, and define a specific lp print command, but this would need a difference printer defined for each option set. Also, all the other print commands then also need defining in this section of smb.conf.

One solution is to give up on Samba and simply pipe the file to lpr on the print server using Cygwin ssh (or any other Windows ssh client). e.g.

type file | ssh cupsserver lpr -pLaserjet-6P -o cpi=11.5 -o lpi=6 -o page-top=33
articles/cupsprinting.txt · Last modified: 2010/02/08 08:54 by timallen