APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS














(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



printer filters


What is this stuff?

If this isn't exactly what you wanted, please try our Search (there's a LOT of techy and non-techy stuff here about Linux, Unix, Mac OS X and just computers in general!):



From - Thu Jan 13 06:35:55 2000
Xref: world comp.unix.sco.misc:113866
Path: world!newsfeed.mathworks.com!arclight.uoregon.edu!logbridge.uoregon.edu!nntp.upenn.edu!news.misty.com!shady!shady!not-for-mail
From: kevin@shady.com (Kevin Smith, ShadeTree Software, Inc.)
Newsgroups: comp.unix.sco.misc
Subject: Re: print filters
Date: 12 Jan 2000 22:58:22 -0500
Organization: ShadeTree Software, Inc.
Lines: 160
Message-ID: <85jigu$b41@shady.shady.com> 
References: <38797A88.423347FF@squonk.net> <85d0sl$a5k@shady.shady.com> <387B2968.C656F3CE@squonk.net> 
NNTP-Posting-Host: localhost.shady.com
X-Mozilla-Status: 8010
X-Mozilla-Status2: 00000000

In article <387B2968.C656F3CE@squonk.net> "Brian K. White" <linut@squonk.net> writes:
>Kevin Smith wrote:
>> 
>> In article <38797A88.423347FF@squonk.net> "Brian K. White" <linut@squonk.net> writes:
...
>
>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.

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.
-- 
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




Click here to add your comments

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




/Bofcusm/235.html copyright 1997-2004 (various authors) All Rights Reserved

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.

Publishing your articles here

Jump to Comments



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.



More:
       - OSR5
       - Bofcusm


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress