Pour vérifier si développer un filtre lp était une mission si compliquée
qu'on
en arrivait à écrire des programmes peu lisibles, j'ai développé en 3H
de temps
un filtre pour piloter les imprimantes HP laserjet acceptant le
protocole FTP
(HP8150DN, 4600n par exemple). Ce filtre  permet la sélection A3 /A4 sur
une
HP8150DN.

En mode PCL il accepte quelques options comme l'orientation, le recto,
A3/A4/letter. Pour le moment je l'ai testé avec LaserJet 8150DN en PCL,
PS et TROFF (PDF non testé mais à toute les chances de marcher si
acroread est  dans le PATH du script).

Ce filtre effectue également le filtrage des PDF et du TROFF (pour
imprimer des pages de belles pages de manuels) en utilisant une approche
un peu plus simple que l'approche standard de Solaris. La doc est dans
le début du code. 

Voila ce code est public est il peut être placé sur le site Solaris Fr:

#!/bin/sh

# Name         : ftp_laserjet
# Use as       : Solaris lp model
# Author       : Christian PELISSIER
# Organization : ONERA
# Release      : 1.0
# Date         : 2005/09/07

#
# DESCRIPTION
#

# This script can be used to drive HP LaserJet Postscript/PCL printers
# accepting the FTP protocol on their Jetdirect interface.
# Accepted file types are :
#
# - ISO-8859-1 ASCII  printed as PCL files
# - POSTSCRIPT        printed as Postscript files
# - PDF               filtered by adobe reader, printed as Postscript
files
# - TROFF             filtered by Solaris dpost, printed as Postscript
files
#
# Printers used for test are : HP LaserJet 8150DN and LaserJet 4600n.
#

#
# INSTALL
#

# As root copy this file in the directory /usr/lib/lp/model
# Then do :
# lpadmin -p QUEUE_NAME -v /dev/null -m ftp_laserjet -o dest=PRINT_HOST
\
#         -o banner=never -I any
# accept QUEUE_NAME
# enable QUEUE_NAME
# lpstat -l -p QUEUE_NAME
#
# where QUEUE_NAME is the name of the spool and PRINT_HOST is the
hostname
# or IP address of the printer.

#
# TEST
#

# lp -d QUEUE_NAME -o landscape /etc/group

#
# USAGE
#

# The following lp -o flags are available for ISO-8859-1 ASCII files :
#
# -o landscape
# -o portrait
# -o A4 or -o a4
# -o A3 or -o a3 (8150DN with a feeded A3 tray)
# -o letter
# -o duplex
# -o simplex


#
# INTERFACE REQUIREMENT
#

# This script is run as 'lp' on the print server if the job came in via
the
# network.  It runs as the submitting user if the job is local.  You
should
# also note that the data files are owned by the user running the
script.
#
# Command Line Arguments:
#       $0      - .../{printer}
#       $1      - request-id
#       $2      - user
#       $3      - title
#       $4      - copies
#       $5      - options (lp -o)
#       $6+     - file list
# Environment Variables:
#       CHARSET         - the character set to use
#       FILTER          - fast filter to inline on the way to the
printer
#       LC_COLLATE      - I18n
#       LC_CTYPE        - I18n
#       LC_MESSAGES     - I18n
#       LC_MONETARY     - I18n
#       LC_NUMERIC      - I18n
#       LC_TIME         - I18n
#       PATH            - default path (/usr/sbin:/usr/bin)
#       SPOOLER_KEY     - used by lp.tell for backchannel to lpsched
#       TERM            - printer type
#       TZ              - our timezone
# File Descriptors:
#       0       - don't recall
#       1       - printer device (use /dev/null for network attached
printers)
#       2       - backchannel to lpsched
# Signals:
#       15      - we have been asked to exit
#
# Exit Codes:
#       0       - success
#       1 - 127 - failure, don't restart
#       128     - don't use
#       >128    - failure, wait or restart
#

trap 'eval lpexit 15' 15

: ${TMPLP:=/tmp}
: ${SPOOLDIR:=/usr/spool/lp}
PATH=/bin:/usr/bin:/usr/sfw/bin:/opt/sfw/bin:/usr/local/bin

if [ $# -lt 5 ] ; then
        echo "wrong number of arguments to interface program" 1>&2
        exit 1
fi

printer=`basename $0`
request_id=$1
user_name=$2
title=$3
copies=$4
option_list=$5

logger -p lpr.notice -t "ftp_laserjet: ${request_id}" "OPTIONS :
${option_list}"
shift 5
files="$*"

#
# Parse -o flag=value options
#
parse ()
{
        echo "`expr \"$1\" : \"^[^=]*=\(.*\)\"`"
}

#
# Send file $2 to printer whom IP or hostname is $1
#
ftpsend ()
{
        ftp -n $1 <<- endftp!
        user ftp ftp
        put $2
        quit
        endftp!
}

#
# Exit
#
lpexit ()
{
        rm -f ${TMPLP}/pclinit.$$
        rm -f ${TMPLP}/$printfile
        exit 0
}

#
# PCL Escape command used to init printer
#
pclinit ()
{
        PCL0="\033E"            # INIT
        PCL1="\033&k2G"         # CR=CR, LF=CR+LF, FF=CR+FF
        PCL3="\033&k3G"         # CR=CR+LF, LF=CR+LF, FF=CR+FF
        PCL4="\033(0N"          # ISO 8859-1
        PCL5="\033&l${1}X"      # Nombre de copies via $1
        PCL6="\033&l${3}A"      # A4 $3=26, A3 $3=27, Letter $3=2
        PCL7="\033&l${2}O"      # Portrait $2=0, Paysage $2=1
        PCL8="\033&l${4}S"      # Simplex $4=0, VDuplex $4=1, HDuplex
$4=2
        echo "$PCL0$PCL1$PCL4$PCL5$PCL6$PCL7$PCL8\c" >
${TMPLP}/pclinit.$$
}

#
# Default values
#
nobanner="no"
nofilebreak="no"
orientation=0           # Portrait PCL
arlandscape=""          # Portrait PDF
size=a4                 # PDF A4
papersize=26            # PCL A4
duplex=1                # Duplex PCL

inlist=
for i in ${option_list}
do
        case "${inlist}${i}" in

        nobanner )
                nobanner="yes"
                ;;

        nofilebreak )
                nofilebreak="yes"
                ;;

        landscape )
                orientation=1
                arlandscape="-landscape"
                ;;

        portrait )
                orientation=0
                ;;

        A3|a3 )
                papersize=27
                size=a3
                ;;

        A4|a4 )
                papersize=26
                size=a4
                ;;

        letter )
                papersize=2
                size=letter
                ;;

        vduplex|duplex )
                duplex=1
                ;;

        hduplex )
                duplex=2
                ;;

        simplex )
                duplex=0
                ;;

        dest=* )
                dest="`parse ${i}`"
                ;;

        * )
                echo "unrecognized \"-o ${i}\" option check the option,
resubmit if necessary printing continues" 1>&2
                ;;
        esac
done

#
# Create the PCL init file
#

pclinit 1 $orientation $papersize $duplex
#pclinit $copies $orientation $papersize $duplex

#
# Initialyze filters used to translate common format others than PS or
PCL
#
TROFF2PS="/usr/lib/lp/postscript/dpost"
PDF2PS="acroread  -toPostScript -level2 -fast $arlandscape -size $size"


#
# Create a banner (unneeded)
#

#
# Process the files
#

node=`uname -n`
printfile=${TMPLP}/${node}.$$

i=1
while [ $i -le $copies ]
do
        for file in $files
        do
                if [ -r "${file}" ]
                then
                        # Filter
                        magic=`head -1 "$file"`
                        case  "$magic" in
                        'x T post' )
                                $TROFF2PS "$file" > $printfile
                                ;;
                        %!PDF-* )
                                $PDF2PS < "$file" > $printfile
                                ;;
                        %!PS* )
                                cp "$file" $printfile
                                ;;
                        * )
                                cat  ${TMPLP}/pclinit.$$ "$file" >
$printfile
                        esac
                        ftpsend $dest $printfile
                fi
        done
        i=`expr $i + 1`
done
rm -f ${TMPLP}/pclinit.$$ ${TMPLP}/$printfile
exit 0


-- 
Christian Pélissier
Office National d'Études et de Recherches Aérospatiales
BP 72 92322 Chatillon
Tel: 33 1 46 73 44 19, Fax: 33 1 46 73 41 50

_______________________________________________
Solaris_fr liste de diffusion en français pour Solaris, sur toutes architectures
Solaris_fr@x86.sun.com
http://x86.sun.com/mailman/listinfo/solaris_fr

Reply via email to