#!/bin/bash
# uses ghostscript to combine 2 pdfs into 1. Argument order is very important

#if forced, overwrite $4
if [  $1 == "-f" ];then 
    echo combining $2 $3 into $4
    `gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$4 $2 $3`
else
#check if output file exists, don't overwrite
    if [ -e $3 ];then 
	echo  output file $3 exists, give -f option to force creation
    else
	echo combining $1 $2 into $3
	`gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$3 $1 $2`
           fi
fi

