[cups.general] A2ps filter for text

Eric PEYREMORTE eric.peyremorte at iut-valence.fr
Tue Jul 12 02:54:18 PDT 2005


Thank you very much, no problem for comment, the code doesn't seem too 
hard to understand!!
many thanks :-D

Kevin Ivory wrote:

> On 2005-07-06 18:26, Eric PEYREMORTE wrote:
>
>> Does anyone know how to use a2ps as default filter for text files ?
>
>
> I have done it and you can use my filter as a template for a similar
> or more general one. Sorry, all comments are in German - but I hope
> you will get the idea simply by reading the code. I needed a hack to
> get landscape to work correctly. I am not sure if still needed for
> recent cups versions.
>
> 1. /etc/cups/mime.convs
> application/x-cshell    application/postscript  33      texttops-a2ps
> application/x-perl      application/postscript  33      texttops-a2ps
> application/x-shell     application/postscript  33      texttops-a2ps
> text/plain              application/postscript  33      texttops-a2ps
> text/html               application/postscript  33      texttops-a2ps
>
> 2. /usr/lib/cups/filter/texttops-a2ps
>
> #!/bin/bash
> # /usr/lib/cups/filter/texttops-a2ps
> # 2001-10-23 ki
> #   Das mit cups gelieferte texttops füllt die komplette Seite ohne 
> Zusatzinfo.
> #   Dieses Skript versucht soviele Defaults wie möglich zu verwenden.
> #   Problematisch:
> #     * file modification time: current time (-> left-title=)
> #     * file name: temporary name (-> use $3)
> #     * user: lp daemon (-> use $2 to extract passwd gecos field)
> #  Bemerkung: CUPS-Filter müssen berücksichtigen, dass entweder fünf 
> oder sechs
> #       Argumente verwendet werden: Wenn lpr Stdin erhält, sind es fünf.
> #       Wenn lpr als Argument einen Dateinamen bekommt, wird dieser 
> als sechstes
> #       Argument an den Filter weiter gereicht. a2ps kann problemlos 
> mit beiden
> #       Fällen umgehen.
> #       Werden lpr mehrere Dateinamen übergeben, kommt nur der erste als
> #       Argument im Filter an. :-(
> # 2002-04-02 ki A2PS_BIN und A2PS_OPT Variablen, --pretty-print wg 
> HTML-Problem
> # 2004-07-26 ki landscape Behandlung mit a2ps statt mit Cups texttops
> export LANG=german LC_TIME=de_DE
> unset TZ
> A2PS_BIN=/usr/bin/a2ps
> A2PS_OPT="--left-title= --medium=A4 --pretty-print=plain --footer= 
> --columns=1"
> user="$2"
> title="$3"
> A2PS_OPT="$A2PS_OPT --center-title=${title} --title=${title}"
> # Variable fullname wg Leerzeichen hier mit Anführungszeichen 
> referenzieren
> fullname="$(/bin/grep ^$user: /etc/passwd|/usr/bin/cut -f 5 -d :)"
> # wenn da nichts drin steht, nehmen wir $user
> fullname=${fullname:=$user}
> # wenn da nichts drin steht, nehmen wir 'Unknown'
> fullname=${fullname:='Unknown'}
> #A2PS_OPT="$A2PS_OPT --define=user.name=${fullname}"
> case "$5" in
>  *landscape* )
> # Sowohl a2ps als auch Cups texttops haben miserable landscape Defaults..
> # Leider muss die Seitendrehung wieder entfernt werden, da sie von 
> Cups spaeter
> # noch einmal durchgefuehrt wird.
> # Typische Werte fuer chars-per-line sind 112 oder 132. Wir verwenden 
> mehr.
>        A2PS_OPT="$A2PS_OPT --landscape --chars-per-line=160"
>        $A2PS_BIN $A2PS_OPT --define=user.name="${fullname}" --output=- 
> $6 |\
>          /bin/grep -v '^sh 0 translate 90 rotate$'
>        ;;
>  * )
>        A2PS_OPT="$A2PS_OPT --portrait --chars-per-line=80"
>        $A2PS_BIN $A2PS_OPT --define=user.name="${fullname}" --output=- $6
>        ;;
> esac
>
>
> Hope this helps,
> Kevin






More information about the cups mailing list