corey@blake.acs.washington.edu (Corey Satten) (06/14/89)
As an alternative to both Preview and Yap, I offer the net this little shell script, pwin, which despite its limitations, I find more useful than either Preview or Yap. I'm posting it in case others find it equally helpful and/or educational. Obviously, this is not the last word in previewing on NeXTs - I hope that it (along with comments from the net) helps inspire NeXT to provide a single previewer application in release 1.0 which combines the good qualities of pwin, Yap, and Preview. Some of the advantages and disadvantages of pwin are in the commentary beginning the script. Happy Previewing Hmm, while I'm at it, why don't I also give you ps-2sided, a shell script which splits a single conforming postscript file into two output files suitable for printing 2-sided. (First print the odd pages, then turn over the stack and print the even pages.) It's a bit of a kludge, but what the heck, it works and it's a real paper-saver. ps-2sided has been tested against the output of enscript, Edit, WriteNow, ptroff. Hopefully I didn't break it during the final clean-up before posting... In the archive below, find: pwin - the previewr shell script ps-2sided - the 2-sided postscript munger ps-even-pages - part of ps-2sided ps-odd-pages - part of ps-2sided ps-2sided.l - the manpage for ps-2sided Corey Satten corey@cac.washington.edu : ----- cut here ----- cut here ----- cut here ----- cut here ----- : This is a "shell archive". Save everything after the cut mark : in a file called thisstuff, then feed it to sh by typing sh thistuff. : SHAR archive format. Archive created Tue Jun 13 09:17:55 PDT 1989 echo x - pwin echo '-rwxr-xr-x 1 corey 3846 Jun 12 18:00 pwin (as sent)' sed 's/^X//' >pwin <<'+FUNKY+STUFF+' X#!/bin/sh X# X# Bypassing NextStep eitirely, open a connection to the PostScript window X# server (with pft), create a window, define a suitable showpage operator X# and then send the user's postscript on down to the window server. X# X# This is not good, desirable, or right (see disadvantages below). This X# kludge would not be necessary if NeXT provided a suitable previewer. X# (Or a suitable graphics interface from shell programs in general.) X# Feel free to voice your opinion -- NeXT seems to be listening. X# X# Advantages over one or both NeXT-provided previewers: (Yap and Preview): X# 1 - starts quickly from the command line and reads standard input X# or files listed as arguments (regardless of their names). X# 2 - correctly previews ANYTHING which will print (I hope at least) X# not just conforming postscript or single page documents. X# 3 - waits at end-of-page. X# 4 - allows postscript abort when you type ^C (interrupt). X# X# Bugs and disadvantages: X# 1 - bypasses NextStep - the window you get doesn't act like a X# NeXT window in any of the desirable ways you would expect. X# Also, the preview window is higher than the dock - be careful X# if you click other windows on top of it - these can hide all X# or part of your dock. (Usually, these unusually high windows X# can be lowered again if you hide them with command-h, though.) X# 2 - can't go to previous page, or to arbitrary page. X# 3 - busy waits at each showpage operator. X# 4 - doesn't go away without the user typing ^C X# 5 - will die if your document has any of my variable names in it X# though I've tried to make that unlikely. X# X# Author: X# Corey Satten, corey@cac.washington.edu, 6/8/89 X# X# Note, if you provide the -r flag, the RIGHT mouse button will be used X# instead of the left. Besides the novelty of actually being able to use X# the right button, this is more benign if you accidently mouse outside X# pwin's window since it doesn't normally have any effect. X XRIGHT= Xfor i in $*; do X case $1 in X -r) RIGHT=right; shift;; X *) break;; X esac Xdone X Xcase $# in X 0) set x -; shift;; # no files? use stdin Xesac X X( X# download initial environment Xecho ' X /MEssageFOnt 8 def X /BOrder 5 def % border width X /SAveGS gstate def % declare SAveGS as a gstate X /MYWIdth 612 def % window width X /MYHEight 792 def % window height X /Courier findfont MEssageFOnt scalefont setfont X /showpage { % showpage waits for mouse then clears X gsave X SAveGS setgstate % restore initial state for clear X % X 0 BOx % darken border X 20 MYHEight BOrder sub MEssageFOnt sub moveto X 0 setgray % use black for message in top corner X (CLICK FOR NEXT PAGE OR INTERRUPT TO QUIT) show X % X {'$RIGHT'buttondown {exit} if} loop % wait for mouse down X 1 setgray % use white paint ... X 0 0 MYWIdth MYHEight rectfill % ... and clear the screen X {'$RIGHT'buttondown not {exit} if} loop % then wait for mouse back up X 1 3 div BOx % lighten border X grestore X } def X /erasepage {showpage} def % some docs use copypage+showpage X /BOx { % draw window border box X gsave X setgray X BOrder 2 mul setlinewidth X 0 0 moveto X 0 MYHEight rlineto X MYWIdth 0 rlineto X MYWIdth 0 lineto X 0 0 lineto X stroke X grestore X } def X /MYWIn 100 20 MYWIdth MYHEight Nonretained window def X Above frontwindow MYWIn orderwindow X MYWIn windowdeviceround X 1 3 div BOx X SAveGS currentgstate pop X ' X# now, for each file (or just once for stdin) Xfor FILE in ${1+"$@"}; do X echo ' X SAveGS setgstate % setup initial state X ' X cat $FILE || kill -9 0 X done X# now display the interrupt to quit message Xecho ' X SAveGS setgstate % restore initial state for clear X 0 BOx X 20 MYHEight BOrder sub MEssageFOnt sub moveto X 0 setgray X (INTERRUPT TO QUIT) show X % MYWIn termwindow % remove window X ' Xsleep 10000 X) | pft +FUNKY+STUFF+ chmod u=rwx,g=rx,o=rx pwin ls -l pwin echo x - ps-2sided echo '-rwxr-xr-x 1 corey 1362 Jun 8 12:14 ps-2sided (as sent)' sed 's/^X//' >ps-2sided <<'+FUNKY+STUFF+' X: ' X: ps-2sided takes zero or more "conforming" PostScript files and splits X: them into 2 output files such that after the first is printed, the pages X: can be turned over and printed again with the second. The result is X: proper 2sided printing. X: X: The output is non-conforming so that no page reversing will happen. X: X: Corey Satten, corey@cac.washington.edu X: ' X XOUT1=ps-out1 # name of first printing XOUT2=ps-out2 # name of second printing X X: > $OUT1 # initialize output files X: > $OUT2 X XTMP=/tmp/ps-2s$$ Xtrap "rm -f $TMP; exit 0" 0 1 2 13 15 X Xcase $# in X 0) INFILES=$TMP; cat > $TMP;; # create TMP only if input is stdin X *) INFILES="$@";; Xesac X XTHIS=ps-odd-pages XOTHER=ps-even-pages X Xfor i in $INFILES; do # first pass X (echo %!; $THIS $i) >> $OUT1 # emit the front sides X PAGES=`grep '^%%Pages:' $i` # check if "odd # of pages" X PAGES=`(set $PAGES; echo $1 $2)` X case "$PAGES" in # if so, do next file differently X *[13579]) PL="$PL O"; TMP=$THIS; THIS=$OTHER; OTHER=$TMP;; X *) PL="$PL E";; X esac Xdone X XTHIS=ps-even-pages XOTHER=ps-odd-pages X Xset $PL Xfor i in $INFILES; do #second pass X (echo %!; $THIS $i) >> $OUT2 # emit the back sides X case $1 in # do next file differently? X O) TMP=$THIS; THIS=$OTHER; OTHER=$TMP;; X E) ;; X *) echo $0: error in saved state 1>&2;; X esac X shift Xdone +FUNKY+STUFF+ chmod u=rwx,g=rx,o=rx ps-2sided ls -l ps-2sided echo x - ps-even-pages echo '-rwxr-xr-x 1 corey 283 Jun 13 08:44 ps-even-pages (as sent)' sed 's/^X//' >ps-even-pages <<'+FUNKY+STUFF+' X: ' X: Delete odd numbered pages from conforming (PSrev-able) PostScript X: Corey Satten, corey@cac.washington.edu 3/19/89 X: ' X Xsed ' Xs/^%%Trailer$/%%Page:Trailer 9999999999 9999999999/ X/^%%Page:.*[13579]$/,/^%%Page:/ { X /^%%Page:.*[13579]$/d X s/^%%/%-%/p X d X } Xs/^%%/%-%/ X' ${1+"$@"} +FUNKY+STUFF+ chmod u=rwx,g=rx,o=rx ps-even-pages ls -l ps-even-pages echo x - ps-odd-pages echo '-rwxr-xr-x 1 corey 284 Jun 13 08:45 ps-odd-pages (as sent)' sed 's/^X//' >ps-odd-pages <<'+FUNKY+STUFF+' X: ' X: Delete even numbered pages from conforming (PSrev-able) PostScript X: Corey Satten, corey@cac.washington.edu 3/19/89 X: ' X Xsed ' Xs/^%%Trailer$/%%Page:Trailer 9999999999 9999999999/ X/^%%Page:.*[02468]$/,/^%%Page:/ { X /^%%Page:.*[02468]$/d X s/^%%/%-%/p X d X } Xs/^%%/%-%/ X' ${1+"$@"} +FUNKY+STUFF+ chmod u=rwx,g=rx,o=rx ps-odd-pages ls -l ps-odd-pages echo x - ps-2sided.l echo '-rw-r--r-- 1 corey 1087 Jun 13 09:00 ps-2sided.l (as sent)' sed 's/^X//' >ps-2sided.l <<'+FUNKY+STUFF+' X.TH PS-2SIDED LOCAL X.UC 4 X.SH NAME Xps-2sided \- split PostScript data for front and back side printing X.SH SYNOPSIS X.B ps-2sided X[ infiles ] X.SH DESCRIPTION X.PP X.I ps-2sided Xsplits a "conforming" PostScript file into two files, X.I ps-out1 Xand X.I ps-out2 Xsuch that printing first X.I ps-out1, Xthen flipping the stack over and Xre-printing with X.I ps-out2 Xachieves proper 2-sided printing. X.PP XIf several files are input, they are printed as if they had all been Xin a single file \(em that is, if the first file has an odd number of pages, Xthe first page of the second file will be rendered on the back of the Xlast page of the first file. X.SH FILES X.nf Xps-even-pages filter to extract even pages Xps-odd-pages filter to extract odd pages Xps-out1 output of front pages (printed first) Xps-out2 output of back pages (printed second) X.fi X.SH BUGS XAssumes that pages stack in reverse order (such as on an Apple LaserWriter Xor a NeXT printer). Output is made non-conforming so as not to be X.I ps-rev'd Xbefore printing. The act of printing the second side does the necessary Xpage reversal. +FUNKY+STUFF+ chmod u=rw,g=r,o=r ps-2sided.l ls -l ps-2sided.l exit 0
langz@asylum.SF.CA.US (Lang Zerner) (06/15/89)
In article <2398@blake.acs.washington.edu> corey@blake.acs.washington.edu (Corey Satten) writes: > > >Hmm, while I'm at it, why don't I also give you ps-2sided, a shell script >which splits a single conforming postscript file into two output files >suitable for printing 2-sided. (First print the odd pages, then turn over >the stack and print the even pages.) It's a bit of a kludge, but what the >heck, it works and it's a real paper-saver. WARNING! WARNING! (Danger Will Robinson and all that) Some laser printers, including LN03s, may experience damage if you run printed pages through them again. The reason I've been given is that some toner particles already on the sheet will dislodge whilst passing through a second time, accumulating in the moving parts of the printer. Do as thou wilt. -- Be seeing you... --Lang Zerner ARPA:langz@athena.mit.edu MX:langz@asylum.sf.ca.us UUCP:bionet!asylum!langz "...and every morning we had to go and LICK the road clean with our TONGUES!"