From: rideau@mathp7.jussieu.fr (Francois Rideau)
Newsgroups: comp.os.linux.announce
Subject: LPR2 -- printing every other page -- on sunsite
Date: 8 Jul 1994 16:44:20 GMT
Approved: linux-announce@tc.cornell.edu (Lars Wirzenius)
Message-ID: <2vjvp4$snf@hydra.Helsinki.FI>

  I'm announcing here LPR2, a utility to print recto/verso documents on recto
only printers. A LSM description is included, then the utility itself (only
three times as big).

  I've written this utility because I needed it so much. As I do not want to
think I my needs, thoughts and wants are exceptional in any manner, I feel
that other people, somewhere may need such a utility. Thus, I send it to you.
Can you tell me who I can send it to, who will ensure that noone who has
Internet access will suffer from lack of such a program anymore ?

  Thank you for your wonderful work anyway.

--    ,        	                                ,           _ v    ~  ^  --
-- Fare -- rideau@clipper.ens.fr -- Francois-Rene Rideau -- +)ang-Vu Ban --
--                                      '                   / .          --
MOOSE project member. OSL developper.                     |   |   /
Dreams about The Universal (Distributed) Database.       --- --- //
Snail mail: 6, rue Augustin Thierry 75019 PARIS FRANCE   /|\ /|\ //
Phone: 033 1 42026735                                    /|\ /|\ /

------>8------>8------>8------>8------>8------>8------>8------>8------>8------
Begin2
Title        = lpr2 recto-verso printing utility
Version      = 1.0
Desc1        = This simple program allows printing every other page in a
Desc2        = postscript document, thus allowing recto/verso documents on
Desc3        = recto-only printers. Do use it. Recto/verso books are half
Desc4        = as heavy as recto ones, and you help save forest sin the world.
Desc5        = Easily adaptable /bin/sh script over a small Postscript kernel.
Author       = Fran\,cois Ren\'e B\^an "Far\'e" Rideau \DD\(.ang-V\~u
AuthorEmail  = rideau@ens.fr, rideau@frmap711.mathp7.jussieu.fr
Maintainer   = Fran\,cois Ren\'e B\^an "Far\'e" Rideau \DD\(.ang-V\~u
MaintEmail   = rideau@ens.fr, rideau@frmap711.mathp7.jussieu.fr
Site1        = sunsite.unc.edu
Path1        = /pub/Linux/system/Printing
File1        = lpr2.gz
FileSize1    = 2064
Required1    = /bin/sh
Required2    = a postscript interpreter (typically ghostscript or a printer)
Required2    = lpr (well, not so needed. Edit the file to change)
CopyPolicy1  = GNU General Public License (Copyleft)
Keywords     = Printing, Recto, Verso, Paper, Forest, stopping spillage
Comment1     = Help save the World: stop spilling paper and destroying trees.
Comment2     = Ecology is only global economy.
Comment3     = Again, large documents are made half as heavy and bulky.
Comment4     = You also save space on your shelves and in pack.
RelFiles1    =
RelFiles2    =
RelFiles3    =
Entered      = 08JUL94
EnteredBy    = Far\'e again...
CheckedEmail = rideau@ens.fr
End
------>8------>8------>8------>8------>8------>8------>8------>8------>8------
#!/bin/sh
#
# lpr2 -- Utility to print postscript document on both sides.
# Copyright (c) Frangois-Reni "Fari" Bbn Rideau DDa(.ng-Vu~ 1994
# (rideau@ens.fr,rideau@frmap711.mathp7.jussieu.fr)
#
# This program is distributed under the terms of the GNU General Public License
# There is absolutely NO WARRANTY about what effect it can have on your
# software or hardware. You must keep this notice to distribute it further
#
#
# I'm no Postscript guru. It's my first (and perhaps last) Postscript program.
# I've never read any Postscript book or official documentation. Only gs
# manpage and examples. Postscript looks like a great language to me !
# I developped this program under Linux using Ghostscript 2.6.1 in five
# minutes. I'm actually spending more time documenting it and transforming
# it into a shell utility than I did writing the postscript stuff.
#
# This program works very well for me. It should work on any well-behaved
# Postscript document.
#
#
# Usage:
# To save paper, and lighten you backpack, without lightening your purse by
# buying printers that already print documents on both sides, do print double
# sided documents. Here is a utility to do it with postscript documents.
#
#  To print document "doc.ps", print odd pages on one side and even pages on
# the other.
#  My HP LaserJet 4ML printer issues pages in the "right" order, i.e. the
# page on top exits on top. I have to print even pages first, then odd pages.
# Beware that there may be one odd page more than even pages.
#  Thus, the usage is: feed blank sheets to the printer, mark one corner with
# a pencil to see how you will have to feed sheets again to print the other
# side. Then, print even pages. Insert printed pages
#
# Invocation: lpr2 [options] file
# option	what it means
# -1,-o,--odd 	"print only odd pages"
# -2,-e,--even 	"print only even pages"
# -a,--all	"print even pages; prompt; print odd pages" (default)
# -N,--noprint	"do not send to printer, but to standard output"
# -P,--print	"I changed my mind. Do print"
# -r,--reverse	"print odd pages; prompt; print even pages in reverse
#		 order" (beware: remove last sheet if odd number of pages)
#		NOT IMPLEMENTED YET. If you do implement it, please send
#		me a copy of your modified program.
#
# Beware:
# My printer issues pages in the right order.
# I have to print even pages first, then odd pages so that everything is ok.
#


########################## The Postscript stuff ##############################
redefshowpage ()
{
# have "argument true" or "false" to skip first page or not.
cat <<"END"

%Do or do not print first page
/skipthispage $1 def

% Remember original showpage
/origshowpage /showpage load def

%Redefine showpage...
/showpage {
  skipthispage
  {/skipthispage false def erasepage }
  {/skipthispage true def origshowpage }
  ifelse
} def

END
}


########################## The shell functions ##############################
doprinteven ()
{
  (redefshowpage true ; cat $FILES) | $SENDJOB
}

doprintodd ()
{
  (redefshowpage false ; cat $FILES) | $SENDJOB
}

prompt ()
{
  echo "$@" > /dev/tty
  read < /dev/tty
}

doall ()
{
  prompt '
Feed the printer with blank sheets. If you dunno how to feed the printer
again to achieve printing on the right side, mark corners of the first
sheets with a pencil. When you'"'"'re done, press "Enter".
'
  doprinteven
  prompt '
Wait for the thing to have been printed.
If your printer issues pages in the wrong order, you have a problem.
You'"'"'ll have to reorder everything twice. Next time, try --reverse option.
When everything is printed, feed the printer with the same sheets, but
place the sheets so that the other side will be printed (with the same top
of page). If your document has an odd number of page, add a blank sheet at
the end. Ensure that no one else will use the printer.
When you'"'"'re done, press "Enter".
'
  doprintodd
}

doreverse () 
{
  echo "NOT IMPLEMENTED YET" > /dev/tty
}

calllpr ()
{
  $LPR $LPROPTS
}

######################### The command line interface ########################
LPR="echo lpr"
TODO=doall
LPROPTS=
FILES=
SENDJOB=calllpr

ParseOpts () {
for i ; do
  case "$i" in
	-a|--all)	TODO=doall ; SENDJOB=calllpr ;;
	-r|--reverse)	TODO=doreverse ; SENDJOB=calllpr ;;
	-N)		SENDJOB=cat ;;
	-P)		SENDJOB=calllpr ;;
	-1|-o|--odd)	TODO=doprintodd ;;
	-2|-e|--even)	TODO=doprinteven ;;
	-*)		LPROPTS="$LPROPTS $i" ;;
	*)		FILES="$FILES $i" ;;
  esac
done
}

DoIt () {
  : LPR=$LPR
  : TODO=$TODO
  : SENDJOB=$SENJOB
  : LPROPTS=$LPROPTS
  : FILES=$FILES
  case "$SENDJOB$TODO" in
	catdoall|catdoreverse)	echo "Incompatible options" ; exit 1 ;;
	*)			eval $TODO ;;
  esac
}

ParseOpts "$@"
DoIt
------>8------>8------>8------>8------>8------>8------>8------>8------>8------


--
Mail submissions for comp.os.linux.announce to: linux-announce@tc.cornell.edu
PLEASE remember Keywords: and a short description of the software.
