#!/bin/bash
#slice and rotate
export D=$HOME/.tmp
cp $1 $D
cd $D
rm *sliced*.tif
rm out*.tif
pdf2c4 < `basename $1`
for o in out*.tif; do
	export LEN=`tiffdump out-000.tif | grep Length | cut -f 5 -d ' ' | cut -f 2 -d '<' | cut -f 1 -d '>'`
	slice $o $(( $LEN / 2 )) $LEN
	mv $o.sliced.$(( $LEN / 2)).tif $o.sliceda.tif
	slice $o 0 $(( $LEN / 2 )) 
	mv $o.sliced.0.tif $o.slicedb.tif
done
export ROTATE=g4rotate
rm *.tif.rotated.tif
pdf2c4 < `basename $1`
for o in  out-*.tif.sliced*.tif; do
	export LEN=`tiffdump out-000.tif | grep Length | cut -f 5 -d ' ' | cut -f 2 -d '<' | cut -f 1 -d '>'`
	echo "rotating $o"
	$ROTATE $o 
done
ls out-*.tif.rotated.tif | xargs c42pdf -o `basename $1`
