#!/bin/ksh # This script copies an 8.5x11 sheet of paper with the assumption that # your printer has a 3mm border on the left/right and a 4mm border on # the top/bottom. TEMP_POSTSCRIPT=`tempfile -p copy- -s .ps` DPI=150 PNMFILT="pnmnorm -bvalue 20 -wvalue 235" # Letter-Safe or Letter-Full PAPER=Letter-Safe # pdf or lpr MODE=lpr function die { echo "$1" >&2 exit 1 } function print_usage { echo 'copier [-p paper] [-m mode] [-d dpi] [-h]' echo ' -p|--paper Letter-Safer,Letter-Full' echo ' -m|--mode lpr,pdf' echo ' -d|--dpi 75-600' echo ' -h|--help' exit 0 } TEMP=`getopt -o p:m:d:h --long paper:,mode:,dpi:,help -n copier -- "$@"` if [ $? != 0 ] ; then die "getopt failure; terminating..." ; fi eval set -- "$TEMP" while true ; do case "$1" in -p|--paper) PAPER="$2" ; shift 2 ;; -m|--mode) MODE="$2" ; shift 2 ;; -d|--dpi) DPI="$2" ; shift 2 ;; -h|--help) print_usage ;; --) shift ; break ;; *) die "Unrecognized Argument" ;; esac done # Die if remaining arguments exist for arg do die "Unrecognized argument: $arg" ; done # Scan if [ "$PAPER" = "Letter-Full" ]; then # Full 8.5x11 scanimage -y 279.4 -x 215.9 --resolution $DPI | $PNMFILT | pnmtops -imagewidth 8.5 -imageheight 11 > $TEMP_POSTSCRIPT elif [ "$PAPER" = "Letter-Safe" ]; then # Safer 8.264x10.685 scanimage -y 271.4 -x 209.9 -l 3 -t 4 --resolution $DPI | $PNMFILT | pnmtops -imagewidth 8.264 -imageheight 10.685 > $TEMP_POSTSCRIPT else die "Unsupported PAPER size" fi # Print or Convert if [ "$MODE" = "lpr" ]; then lpr -PC522 $TEMP_POSTSCRIPT elif [ "$MODE" = "pdf" ]; then OUTPUT=`tempfile -p copy- -s .pdf` ps2pdf14 $TEMP_POSTSCRIPT $OUTPUT echo $OUTPUT else die "Unsupported MODE" fi rm $TEMP_POSTSCRIPT