#!/bin/sh

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

## page_count determines the optimal number of signatures in a section
## for imposing the pages of a book.  It determines the number of blank
## pages for several differnt page counts using modular math.

## The input file should be DSC compliant postscript.

x=`grep "^%%Page:" $1 | tail -1 | cut -d " " -f 3 | cut -d '"' -f 2`

## Count the number of pages in the postscript document $1

for count in 28 32 36 40 44 48 52 56 60 64 68
do
    blanks=$[$count - $x % $count]
    echo $blanks $count
done

## Do the math, and output the number of blank pages
## and the count of pages per section in reverse order