Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

print filters

14 views
Skip to first unread message

Brian K. White

unread,
Jan 10, 2000, 3:00:00 AM1/10/00
to
can someone touch upon all the files/actions that need attention in order to
make a new print filter and then have a printer be able to accept the new
input type and print it using the filter ?

I want an epson 24-pin compatible to print postscript using ghostscript. I
have already been using a "lp-replacement" script for a while now that prints
graphics to any of my configured printers using gs, and then lp (with -oraw
for those printers whose interface supports it) and it works great, but I have
some programs that don't let you specify the whole lp command the way netscape
does, and I've avoided the tangle long enough and I want to get it working.

I've tried my damndest to follow the online docs inch by inch but I'm
obviously missing something, and a search of "print filters" got nothing
relevant on the TA library.

so here is what I have done and what has resulted, I hope someone sees and can
tell me what I missed:

FIRST
created a filter script that works the way the manual says it should. IE it
takes user data on stdin and outputs printer data on stdout. I copied it to
/usr/spool/lp/bin/ps2epson and made it's perms/ownership match the other files
there, and tested it for basic functionality by catting a file through it just
to be sure.

here is the filter script
:
exec /usr/local/bin/gs -q -sDEVICE=epson -r180 -dBATCH -dSHORTERRORS -dNOPAUSE
-dSAFER -sOutputFile="-" -

tested with: cat golfer.ps |/usr/spool/lp/bin/ps2epson >/dev/ttya08
and it printed fine


NEXT
created this filter description file for use with scoadmin or lpadmin:
/tmp/ps2epson
Input types: ps
Output types: any
Filter type: slow
Command: /usr/spool/lp/bin/ps2epson

NEXT
tried both scoadmin and lpadmin
in scoadmin-->printers-->printer manager
I selected system-->filters-->new
and added a new filter named "ps2epson" and entered filename "/tmp/ps2epson"
It _seemed_ to like it. *shrug* the new filter is listed in the filters box,
and if I select "examine" it shows me a copy of the description file I made.

then I select the printer I want to use this filter with ("p4") and select
"settings-->advanced-->content types"
the only content type listed at first is "simple"
I select "define new" and type in "ps", then select "add"
now ps is listed in both the defined and supported boxes for printer p4

at this point, as far as I can tell from the manual, I should be able to say
lp -Tps -dp4 golfer.ps
however when I do this I simply get a text printout of the ps file not the
interpreted ps graphics

I also tried the following:
alburner:~# /usr/lib/lpfilter -x -f ps2epson
alburner:~# /usr/lib/lpfilter -f ps2epson -F/tmp/ps2epson
alburner:~# /usr/lib/lpadmin -p p4 -I ps,simple
alburner:~# /etc/init.d/lp stop
Print services stopped.
alburner:~# /etc/init.d/lp start
Print services started.
alburner:~# lp -Tps -dp4 /usr/local/share/ghostscript/5.10/examples/golfer.ps
request id is p4-1247 (1 file)
alburner:~#

I got text again.

the printer interface file is just a copy of "proprinter" renamed to KXP1524
with all instances of echo " changed to echo -e " because I'm using bash
and the top of the script says ":", not "!/bin/sh" and bash's echo wasn't
interpreting the backslash codes.

clues anyone? I don't want to just throw up my hands and decide "oh well, it
can't be done" that's silly. It must work *somehow* it's just that the manual
is worthless as a manual. don't get me wrong, I'm sure that if you knew how it
worked, you'd find that the manual doesn't say anything wrong, but the thing
still does not do the job of telling someone who does not know how to do it,
how to do it.

--
+++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+>+<---<---]>>++.<++.

Brian K. White

unread,
Jan 10, 2000, 3:00:00 AM1/10/00
to
John DuBois wrote:
>
> In article <38797A88...@squonk.net>,
> By adding 'ps' to your printer accept types, you've told the print system that
> it knows how to print a file of type 'ps' directly. Therefore it does not use
> your filter when you give it a ps file. What you need to do is specify that
> your filter produces output of a type specific to the printer. Here's what I
> use:

"ahhhhhh" thank you :)

>
> input types: postscript ps
> output types: epson
> filter type: slow
> command: /usr/spool/lp/bin/ps2epson
> options: MODES draft = -d,MODES low = -d
>
> Then specify that your Epson printer accepts the 'epson' type (and *not* ps).

"ahhhh"

> Now when you use -Tps, the print system finds that there is no printer that can
> print your file directly, but there is a filter it can use that will transform
> the input type (ps) into an output type (epson) that one of your printers can
> handle.

"ohhhh"


> Oh, here's ps2epson:
> -------------------------
> #!/bin/ksh
> # @(#) ps2epson 1.0 92/09/04
> # 92/09/04 john dubois (jo...@armory.com)
>
> device=eps9high
> while getopts :d opt; do
> case "$opt" in
> d) device=epson;;
> ?) print -u2 "Usage: $0 [-d] [file ...]"; exit 1;;
> esac
> done
>
> shift $((OPTIND-1))
> if [ $# -eq 0 ]; then
> # Use stdin if no files named
> set -- -
> else
> # If files given, close stdin so that interpreter won't go interactive
> exec < /dev/null
> fi
>
> # Make normal output go to stderr & printer output go to stdout
> gs -dSAFER -dNOPAUSE -dQUIET -sDEVICE=$device \
> -sOutputFile=/dev/fd/3 "$@" 3>&1 1>&2
> -------------------------
>

92 eh? I was pretty sure this must have been an old, common, faq of faq's
just that I didn't actually find it in any faq's (though truth to tell I only
looked in the on-line manual and the TA website, and tony's site, no faq's per
se)

got it. excellent. thank you very much.

Kevin Smith

unread,
Jan 10, 2000, 3:00:00 AM1/10/00
to
In article <38797A88...@squonk.net> "Brian K. White" <li...@squonk.net> writes:
>...

>
>NEXT
>created this filter description file for use with scoadmin or lpadmin:
>/tmp/ps2epson
>Input types: ps
>Output types: any
>Filter type: slow
>Command: /usr/spool/lp/bin/ps2epson
>
>NEXT
>tried both scoadmin and lpadmin
>in scoadmin-->printers-->printer manager
>I selected system-->filters-->new
>and added a new filter named "ps2epson" and entered filename "/tmp/ps2epson"
>It _seemed_ to like it. *shrug* the new filter is listed in the filters box,
>and if I select "examine" it shows me a copy of the description file I made.
>
>then I select the printer I want to use this filter with ("p4") and select
>"settings-->advanced-->content types"
>the only content type listed at first is "simple"
>I select "define new" and type in "ps", then select "add"
>now ps is listed in both the defined and supported boxes for printer p4
>
>at this point, as far as I can tell from the manual, I should be able to say
>lp -Tps -dp4 golfer.ps
>however when I do this I simply get a text printout of the ps file not the
>interpreted ps graphics
>
>I also tried the following:
>alburner:~# /usr/lib/lpfilter -x -f ps2epson
>alburner:~# /usr/lib/lpfilter -f ps2epson -F/tmp/ps2epson
>alburner:~# /usr/lib/lpadmin -p p4 -I ps,simple
>alburner:~# /etc/init.d/lp stop
>Print services stopped.
>alburner:~# /etc/init.d/lp start
>Print services started.
>alburner:~# lp -Tps -dp4 /usr/local/share/ghostscript/5.10/examples/golfer.ps
>request id is p4-1247 (1 file)
>alburner:~#
>...

I've setup filters on Unixware but not exactly like you're doing but
I may have some insights.

First, I think the '-T<type>' may not be what you expect. From the manual

Tell the print service to print the request on a printer that
supports files of the specified content type. If no printer accepts
this type directly, a filter will be used to convert the file
contents into an acceptable type. If the -r option is specified, a
filter will not be used.

What I think this means is that -Tps will direct the request to a printer
that supports type ps (as you setup with 'lpadmin -I ps,simple'. Since
you've declared that printer p4 accepts type ps it doesn't think it
needs to convert it. The printer does not accept ps which is why you
need a filter invoked.

Try

o Setup a filter with input type ps and output type epson
o Setup p4 to accept types epson and simple.
This way it will accept the filter output or a normal unspecified input.

Now when you invoke lp with -Tps the system will determine that no
printers will accept type ps directly but there is a filter that will
convert from ps to a type supported by the printer and, hopefully,
invoke the filter.

You could just leave the filter output type as 'any' and leave the
printer input type as just simple (or unspecified) and it would still
work but creating a type specific to the type of printer the request
will only work if directed at the right kind of printer. I.e. you would
want the request to fail if you did something like (lp -dlaserjet -Tps)
when your ps filter generates epson output.

In may case on unixware I setup two filters

filter lff:
input=simple, output=lff, type=slow
(This filter strips leading blank pages and trailing blank lines and pages)

filter laserauto:
input=lff, output=fbpcl, type=slow, options='MODES auto = -auto'
(This filter includes setup commands for a laserjet printer and
optionally (-auto arg) sets font and orientation based on the
longest line in the printout)

printer testpcl:
lpadmin -ptestpcl -Ifbpcl

printer testtext:
lpadmin -ptesttext -Ilff

So now if you do a simple print to testtext (lp -dtesttext) the default
input mode is simple but the printer only accepts type lff so the
simile->lff filter is invoked.

If you print to testpcl (lp -dtestpcl) the printer only accepts type fbpcl.
There is no filter for simple->fbpcl but there are filters simple->lff and
lff->fbpcl. The system figurs this out and strings the filters together.

The mode option to the laserauto filter is specified with -yauto on the
lp line (lp -dtestpcl -yauto). If a filter supports the mode specified
in the -y arg (auto in this case) it passes the associated argument to
the filter program (as specified in the Options: line in the filter spec.
--
Do two rights make | Kevin Smith, ShadeTree Software, Philadelphia, PA, USA
a libertarian | 001-215-487-3811 shady.com,kevin bbs.cpcn.com,sysop
| dvtug.org,kevins--Deleware Valley Transit Users Group

Brian K. White

unread,
Jan 11, 2000, 3:00:00 AM1/11/00
to
> ...

> Try
>
> o Setup a filter with input type ps and output type epson
> o Setup p4 to accept types epson and simple.
> This way it will accept the filter output or a normal unspecified input.

Right. per someone elses response, I did this and it works. thanks.
However now it seems I want still more :)

I have a program (not an important one for me, QCAD, gpl cad/drawing app) that
just spits out ps data to the printer you pick (it has an option to print to
file, and of course, since it's gpl and I compiled it myself, I could twiddle
the source, but I'm looking for a real solution) so I set up another printer
named ps4 that uses that same physical printer as p4, but I changed the
printer interface so that the default filter was ps2epson instead of lp.cat.
The idea was to pick "ps4" from inside the app and have graphics come out of
the physical printer p4.
text came out. here is what I did:

I changed this:
-------------------
#Set up the default filter.
if [ -x "${LOCALPATH}/lp.cat" ]
then
LPCAT="${LOCALPATH}/lp.cat 0"
else
LPCAT="cat"
fi

#If we are not using a filter, use the default one.
if [ -z "${FILTER}" ]
then
FILTER="${LPCAT}"
fi


to this:
------------------
LPCAT="${LOCALPATH}/ps2epson"
FILTER="${LPCAT}"


there is a ps2epson script in $LOCALPATH which at that point is
/usr/spool/lp/bin

but I don't see where $FILTER or $LPCAT are even used.

actually a few other apps just make the ps assumption too and if this worked
that would be the best barring either getting magical detection of content
type by the
spooler, or getting a real ps printer.

Kevin Smith, ShadeTree Software, Inc.

unread,
Jan 12, 2000, 3:00:00 AM1/12/00
to
In article <387B2968...@squonk.net> "Brian K. White" <li...@squonk.net> writes:
>Kevin Smith wrote:
>>
>> In article <38797A88...@squonk.net> "Brian K. White" <li...@squonk.net> writes:
...
>

You don't say the source of the interface program. If $FILTER or $LPCAT
are not used just don't bother with them and put your ps2epson whereever
the 'cat' is.

You could also add postscript processing to p4 as an option (-ops).
This is what I do for a laser printer.

At the top of the interface program...

GS=/usr/local/bin/gs
GSOPTS="-q -sDEVICE=ljet3 -dNOPAUSE"

Further down...

...
options=$5
shift; shift; shift; shift; shift
mode=auto
init=_init
for o in $options
do
case $o in
raw|g*)
mode=raw
init=_init_raw
;;
2c)
mode=2c
init=_init_2c
;;
ps)
mode=ps
init=_init_raw
;;
esac
done

Then in the actual print loop

{
# set printer width
# send the file(s) to the standard out $copies times
while [ "$copies" -gt 0 ]
do
# Initialize the printer
$init

for file
do
case $mode in
raw)
cat "$file"
;;
2c)
...
;;
ps)
$GS $GSOPTS -sOUTPUTFILE=- "$file" </dev/null
;;
auto|*)
...
esac
done
done
} | ... cat/netcat/whatever

Postscript output all starts with something like

%!PS-Adobe-3.0

You could read and check the first line to autodetect.
Maybe something like (totally untested mind you)

ps=`line` (this should work since stdin is the file`
case "$ps" in
'$!PS-Adobe'*)
(
echo "$ps"
cat
) | ghostscript...
;;
*)
echo "$ps"
cat
;;
esac

And finially and most importantly, you can't have to printers to the same
device. Each queue is independent and you will mix output if you
are going to a serial or parallel devices. It should work with network
printers as they normally only allow one connection at a time.
Normally though, I've found it best to do one of two things.

1) Handle every possibility in one interface script with -o options.
2) Create an interface script for each option but funnel them all
through one final printer. I.e. each script does

{
... cat file ... whatever
} | lp -dprinter

The 'printer' interface can be totally dumb and just pass the job
through or can take -oraw as a signal to pass stuff through
untouched.

Steve Wertz

unread,
Jan 14, 2000, 3:00:00 AM1/14/00
to

Brian K. White <li...@squonk.net> wrote:

> I changed this:
> -------------------
> #Set up the default filter.
> if [ -x "${LOCALPATH}/lp.cat" ]
> then
> LPCAT="${LOCALPATH}/lp.cat 0"
> else
> LPCAT="cat"
> fi

> #If we are not using a filter, use the default one.
> if [ -z "${FILTER}" ]
> then
> FILTER="${LPCAT}"
> fi


> to this:
> ------------------
> LPCAT="${LOCALPATH}/ps2epson"
> FILTER="${LPCAT}"


> there is a ps2epson script in $LOCALPATH which at that point is
> /usr/spool/lp/bin

> but I don't see where $FILTER or $LPCAT are even used.

In the original proprinter interface script, FILTER si what get
used eventually (set from LPCAT, if not already):

for file
do
0<${file} eval ${FILTER} 2>&1
[ ${nff} = "no" ] && echo "\f\c"
done

-sw

Brian K. White

unread,
Jan 14, 2000, 3:00:00 AM1/14/00
to

heh yeah I saw that after I made the post... don't know why I missed it when I
looked the first time. I've since been made aware that I can't just make two
"printers" that are actually just two interfaces to the same piece of
hardware, and that is why it didn't work. when I tried to print to ps4, p4
always got the job, and so the content didn't get interpreted. (since the app
using the "ps4" printer cannot be told to add "-Tps" to the lp command, or to
use something other than "lp", only to select a printer from a list)

Tony Lawrence

unread,
Jan 14, 2000, 3:00:00 AM1/14/00
to
"Brian K. White" wrote:
> I've since been made aware that I can't just make two
> "printers" that are actually just two interfaces to the same piece of
> hardware

You can, you just have to be more clever about it: you make
THREE printers, one of which points to actual hardware and
runs completely raw- nothing added or massaged, just
straight out to the hardware with whatever it gets. The
other two (or more) printers do whatever they need to do to
the printstream and then send it to the one that actually
does the printing. This "virtual printer" approach is
sometimes easier than writing all the tests and conditions
you need in the scripts, especially when you are working
with some stupid app that can't pass arguments to lp.

--
Tony Lawrence (to...@aplawrence.com)
SCO articles, help, book reviews, tests,
job listings and more : http://www.ApLawrence.com

0 new messages