#!/bin/sh
#
# This script takes the tif files created from scancvt and creates
# individual pdf files and one combined.pdf file from them.  In case
# they are useful, the intermediate PS files created are left as well.
#
# Corey Satten, corey @ cac.washington.edu March 2007

fixup () {	# help pdf2ps get rotation/orientation correct
    awk '{print}
         /^%%BoundingBox:/ \
	 {printf("<</PageSize [%d %d]>>setpagedevice\n", $4, $5)
	 }'
}

for i in "$@"; do
    tiff2ps -a -2 "$i" | fixup > "${i%.tif}.ps"
    ps2pdf ${i%.tif}.ps ${i%.tif}.pdf
    chmod +x ${i%.tif}.ps ${i%.tif}.pdf	# easier on windows
done

if [ $# -gt 1 ] ;then
    tiffcp "$@" combined.tif
    tiff2ps -a -2 combined.tif | fixup > combined.ps && rm combined.tif
    ps2pdf combined.ps
    chmod +x combined.ps combined.pdf	# easier on windows
fi
