#!/bin/sh
## make-envelope.sh
##
## Written 2009 Hal Canary.
## Dedicated to the public domain.
##
## Put the envelope in the printer
## with the front facing you, and
## the opening flap to the right.
##
## Argument is file containing
## "to" address.
FROM="${HOME}/.return-address.txt"
## No 6-3/4 Envelope
WIDTH=6.5 # inches
HEIGHT=3.625 # inches
## No. 10 Envelope
# WIDTH=9.5 # inches
# HEIGHT=4.5 # inches
## Stationary Envelope
#WIDTH=5.5 # inches
#HEIGHT=4 # inches
MARGINLEFT=$(echo "(11-${WIDTH}+.5)*72" \
|bc -l|awk -F. '{ print $1 }')
MARGINRIGHT=$(echo ".25*72"\
|bc -l|awk -F. '{ print $1 }')
MARGINTOPBOTTOM=$( echo "(((8.5-${HEIGHT})/2)+.25)*72"\
|bc -l|awk -F. '{ print $1 }')
echo " MARGINLEFT = $MARGINLEFT points"
echo " MARGINRIGHT = $MARGINRIGHT points"
echo " MARGINTOPBOTTOM = $MARGINTOPBOTTOM points"
TO="$1"
PDF=`mktemp`
mv "${PDF}" "${PDF}.pdf"
PDF="${PDF}.pdf"
TMP=`mktemp`
{ cat "${FROM}";
echo "\n\n" ;
sed 's/^/\t\t/g' <"${TO}"; } > "${TMP}"
cat "$TMP"
paps --landscape \
--bottom-margin=$MARGINTOPBOTTOM \
--top-margin=$MARGINTOPBOTTOM \
--left-margin=$MARGINLEFT \
--right-margin=$MARGINRIGHT \
< "${TMP}" | ps2pdf - - > "${PDF}"
echo "lpr ${PDF}"