#!/bin/bash
#   ps2tiff
#
#     Rasterizes a postscript file, saving as a set of g4 compressed
#     tiff images
#
#     input:  PostScript file
#             root name of output files
#     output: ccitt-g4 compressed tiff binary files for each page
#
#     Restriction: the input PostScript file must be binary

scriptname=${0##*/}

if test $# != 2
then
  echo "usage: " $scriptname " inpsfile outtifroot"
  exit -1
fi

inpsfile=$1
outtifroot=$2

# assert (input postscript filename ends in .ps)
if test ${inpsfile##*.} != ps
then
  echo $scriptname ": " $inpsfile "does not end in .ps"
  exit -1
fi

# choice: output image size depending on resolution
echo "0 neg 0 neg" translate | gs -sDEVICE=tiffg4 -sOutputFile=${outtifroot}%03d.tif -r300x300 -q - ${inpsfile}

# choice: output fixed image size
#echo "0 neg 0 neg" translate | gs -sDEVICE=tiffg4 -sOutputFile=${outtifroot}%03d.tif -g2550x3300 -r300x300 -q - ${inpsfile}

# use this to output to a single multipage tiff file
#tiffcp -c g4 ${outtifroot}*.tif ${outtifroot}.tif

