Re: [OT?] Re: PostScript -> samba -> PDF -> email attachment
On Sat, Feb 21, 2004 at 07:59:58PM -0800, Mike Fedyk wrote:
> I'm more looking for a solution that uses cups/lprng/lpr to queue to
> ps2pdf then to a file that will be emailed to the user.
How about this, which is more than likely a gross hack, but works for me?
*****
/etc/printcap:
*****
pdf|pdfwriter|PDF_Writer
:sd=/var/spool/lpd/pdf
:lp=/dev/null
:if=/usr/local/bin/pdffilter
:mx#0
:sh
:rg=printers
*****
/usr/local/bin/pdffilter:
*****
#!/bin/bash
# pdffilter - take in postcript, output PDF, mail to submitter
# Marc Wilson (msw@cox.net)
# uncomment the following line to enable entirely too much output...
#DEBUG=yes
ENSCRIPT="/usr/bin/enscript"
ENSCRIPTOPTS="-Bh -M letter -p -"
GS="/usr/bin/gs"
GSOPTS="-q -dNOPAUSE -dSAFER -sBATCH -sDEVICE=pdfwrite -r600 -dPDFSETTINGS=/default"
MUTT="/usr/bin/mutt"
LOGGER="/usr/bin/logger"
FACILITY="lpr.debug"
TEMPORARY=`mktemp /tmp/pdfwrite_XXXXXXXX`
JOBNO=000`echo $CONTROL | cut --delim=+ -f 2 | cut --delim=" " -f 1`
CONTROLFILE=hfA`echo $JOBNO | sed 's/.*\(...\)$/\1/'`
MAILTO=`cat $CONTROLFILE | grep ^P | cut --delim="=" -f 2`
INPUTFILE=`cat $CONTROLFILE | grep ^J | cut --delim="=" -f 2`
OUTPUTFILE="/tmp/`echo $INPUTFILE | rev | cut --delim="/" -f 1 | rev`.pdf"
if [ ! -x "$MUTT" ] || [ ! -x "$ENSCRIPT" ] || [ ! -x "$GS" ]; then exit 1 ; fi
if [ "$DEBUG" ]; then
$LOGGER -p $FACILITY pdf: TEMPORARY = $TEMPORARY
$LOGGER -p $FACILITY pdf: JOBNO = $JOBNO
$LOGGER -p $FACILITY pdf: CONTROLFILE = $CONTROLFILE
$LOGGER -p $FACILITY pdf: MAILTO = $MAILTO
$LOGGER -p $FACILITY pdf: INPUTFILE = $INPUTFILE
$LOGGER -p $FACILITY pdf: OUTPUTFILE = $OUTPUTFILE
fi
# save the input stream
cat > $TEMPORARY
# let's make sure of what this job is BEFORE we try to print it, shall we?
if (file $TEMPORARY | grep PostScript >/dev/null 2>&1); then
# ok, it's PS, use ghostscript to print it
if [ "$DEBUG" ]; then $LOGGER -p $FACILITY pdf: Input to PDF filter is PostScript ; fi
$GS $GSOPTS -sOutputFile="$OUTPUTFILE" $TEMPORARY
if [ "$DEBUG" ]; then $LOGGER -p $FACILITY pdf: Mailing result to $MAILTO ; fi
$MUTT $MAILTO -s "Your PDF print job '$INPUTFILE'" -a "$OUTPUTFILE" < /dev/null
rm $TEMPORARY
exit 0
elif (file $TEMPORARY | grep text >/dev/null 2>&1); then
# not PS, file(1) thinks it's text so go with that
if [ "$DEBUG" ]; then $LOGGER -p $FACILITY pdf: Input to PDF filter is ASCII text ; fi
$ENSCRIPT $ENSCRIPTOPTS $TEMPORARY | $GS $GSOPTS -sOutputFile="$OUTPUTFILE" -
if [ "$DEBUG" ]; then $LOGGER -p $FACILITY pdf: Mailing result to $MAILTO ; fi
$MUTT $MAILTO -s "Your PDF print job '$INPUTFILE'" -a "$OUTPUTFILE" < /dev/null
rm $TEMPORARY
exit 0
else
# it's not PostScript, and it's not text, so fail out
if [ "$DEBUG" ]; then $LOGGER -p $FACILITY pdf: ERROR: Unrecognizable input to PDF filter ; fi
exit 1
fi
Ugly, huh? But it works.
--
Marc Wilson | If God had intended Man to Walk, He would have given
msw@cox.net | him Feet.
Reply to: