Print filters are a little used feature of Sys V printing. These are actually quite powerful and can allow for such things as printing only specific pages, handling printer faults, or converting specific input types to something the printer knows how to handle.
Unfortunately, the SCO manual page for print filters is a bit vague.
One of the other things to know is that if you have a filter, lp will accept other option flags that will be passed to your filter (if you do NOT have a filter, the job will fail if these options are used).
-y mode : mode is up to you, might be "color", "nocolor" or whatever your filter understands.
-P pagelist : Let's you select specifc pages to print. I've never tried this; it's not clear from the manual whether lp selects the pages or your filter has to do that work. A Sun man page says:
Each page range consists of a pair of numbers separated by a dash, or a single number. (For example, 1–5,6,8,10 indicates pages 1 through 5, plus pages 6, 8, and 10.) However, whatever value was given in the -P option to a print request is passed unchanged.
That would seem to imply that lp does the selection, but then why do you need a filter? Confusing..
SCO happens to include an example in their man pages and a ksh script (/usr/spool/lp/bin/pages) that clears up the mystery - your filter needs to do the selection processing. I'm not sure anyone has ever used it, but there it is.
The most important thing to glean from this newsgroup post is the part about what "printer accept types" mean - the only time you'd mess with that is, for example, when you have a printer that already knows how to handle either Postscript or PCL automatically. Otherwise, don't touch that.
Newsgroups: comp.unix.sco.misc Subject: Re: print filters From: spcecdt@deeptht.armory.com. (John DuBois) Message-ID: <Xeke4.16029$7L.718133@tw11.nn.bcandid.com> Date: Mon, 10 Jan 2000 12:27:36 GMT In article <38797A88.423347FF@squonk.net>, Brian K. White <linut@squonk.net> wrote: >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 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: 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). 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. Oh, here's ps2epson: ------------------------- #!/bin/ksh # @(#) ps2epson 1.0 92/09/04 # 92/09/04 john dubois (john@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 ------------------------- John -- John DuBois spcecdt@armory.com. KC6QKZ http://www.armory.com./~spcecdt/ From - Mon Jan 10 15:25:24 2000 From: kbs=cusm@shady.com (Kevin Smith) Newsgroups: comp.unix.sco.misc Subject: Re: print filters Date: 10 Jan 2000 11:20:37 -0500 Message-ID: <85d0sl$a5k@shady.shady.com> In article <38797A88.423347FF@squonk.net> "Brian K. White" <linut@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
More Articles by Tony Lawrence - Find me on Google+
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar