User Tools

Site Tools


articles:cupsprinting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
articles:cupsprinting [2009/02/11 12:28] timallenarticles:cupsprinting [2010/02/08 08:54] (current) timallen
Line 71: Line 71:
 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. 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 :+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   aptitude install libcupsys2-dev smbclient
   cd /tmp   cd /tmp
Line 149: Line 150:
  
 ===== Putting It All Together ===== ===== Putting It All Together =====
 +
  
  
 ==== Sambafax ==== ==== Sambafax ====
-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. {{articles:sambafax.txt|This modified version}} 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. +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. 
 + 
 +<file> 
 +#!/bin/sh 
 +#  
 +# 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) 
 +PRINTSYSTEM="CUPS" 
 + 
 +# Constants 
 +SENDMAIL="/usr/sbin/sendmail" 
 + 
 +# Make up a temporary file using PID 
 +FAXFILE=/tmp/sambafax.$$ 
 + 
 +# Fax number format 
 +# Match FAX : '01234 567890' 
 +# Deals with newlines in string and 0xad as hyphen 
 +PARSE=" 
 +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 : 
 +  do 
 +    case "$1" in 
 +        -n) Username="$2" 
 +            shift ; shift 
 +            ;; 
 +        -h) Hostname="$2" 
 +            shift ; shift 
 +            ;; 
 +        -*) shift 
 +            ;; 
 +         *) break 
 +    esac 
 +  done 
 +  cat >${FAXFILE} 
 +else 
 +# CUPS 
 +  Username="$2" 
 +  cat "$6" >${FAXFILE} 
 +fi 
 + 
 +# If the samba user is anonymous then send mails to the postmaster 
 +if [ "${Username}" = "nobody" ]; then 
 +  MailTo="postmaster@fleet.dcallen.co.uk" 
 +else 
 +  MailTo="${Username}@fleet.dcallen.co.uk" 
 +fi 
 + 
 +# 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} 
 +else 
 +  sendfax -n -D -m -f ${MailTo} -d ${FAXNUM} ${FAXFILE} 
 +fi 
 + 
 +# Remove the temp file 
 +# rm -f ${FAXFILE} 
 + 
 +# End of file 
 +</file> 
 + 
  
 First, copy the sambafax script to ''/usr/lib/cups/backend'', then First, copy the sambafax script to ''/usr/lib/cups/backend'', then
Line 233: Line 331:
   BrowseAllow @LOCAL   BrowseAllow @LOCAL
   BrowsePoll server.domain.com   BrowsePoll server.domain.com
 +
 +===== 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:
 +
 +  - 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.
 +  - Any printer options set with ''lpoptions'' (see above) are ignored.
 +  - 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