#!/bin/sh
# ps2booklet:
#
# Process a Postscript file containing booklet-sized (5.5in x 8.5in)
# pages, in order, to 2-up letter-sized pages
#
# The output pages can be duplex printed (short-edge) and folded to
# make a booklet
#
me=`basename "$0"`
usage="Usage: $me [size] file"
# The paper size of the final output (ops) may be a program argument
# or be part of the command name itself
#
if [ $# -gt 1 ]
then
ops="$1"
shift
else
ops=`echo "$0" | sed -e 's/.*ps2//'`
fi
if [ -z "$1" ]
then
echo "$me: Oops: no input file specified" >&2
echo "$usage" >&2
exit 1
fi
if [ ! -f "$1" ]
then
echo "$me: Oops: no such file: '$1'" >&2
echo "$usage" >&2
exit 2
fi
if [ -z "$ops" ]
then
echo "$me: Oops: no paper size specified ($0|$ops)" >&2
echo "$usage" >&2
exit 3
fi
case $ops in
booklet | 8555 | stmt )
in='statement'
out='letter'
layout='2:0L(8.5in,0)+1L(8.5in,5.5in)'
;;
11x17 | 1117 | letter )
in='letter'
out='tabloid'
layout='2:0L(11in,0)+1L(11in,8.5in)'
;;
cd | cdbooklet )
in='cd (12x12cm)'
out='letter'
layout='2:0L(11in,0)+1L(11in,12cm)'
;;
4up )
in='letter/4 (4.25"x5.5")'
out='letter'
layout='8:0(0,0)+1(4.25in,0)+4(0,-5.5in)+5(4.25in,-5.5in),' \
' 2(0,0)+3(4.25in,0)+6(0,-5.5in)+7(4.25in,-5.5in)'
;;
*)
echo "$me: Oops: unknown ouput paper size ($ops)";
exit 1
;;
esac
echo "** Page Sizes: $in --> $out" >&2
psbook "$1" | pstops -p$out "$layout"