#!/bin/sh

## Author:  Rick Holbert
## email:   rholbert@colug.net
## Date:    14 June 2001

## ps2book is a short script to produce trade sized paperback books
## from postscript input.  The postscript file should have DSC page
## tags, and be formatted for US letter size paper.

if [ "$1" == "" ] ; then
	echo "usage:  ps2book ps_file

where ps_file is a DSC compliant input postscript file
(without the .ps extension)
"
	exit 0
fi


pages=`grep '%%Page: ' $1.ps | \
       tail -1 | \
       cut -d ' ' -f 3`

echo "I found " $pages " pages in this document."

if [ $pages -le 68 ] ; then
  psbook $1.ps | \
  psnup -2 -pletter /dev/fd/0 | \
  ps2pdf /dev/fd/0 $1_book.pdf
else
  psbook -s`./page_count $1.ps | \
            sort -g -k 1,1 -k 2r,2 | \
            head -1 | \
            cut -d ' ' -f 2` $1.ps | \
  psnup -2 -pletter /dev/fd/0 | \
  ps2pdf /dev/fd/0 $1_book.pdf
fi
