creating pdf files from lpd

Jeremy Fowler jfowler at westrope.com
Wed Nov 14 15:45:59 CST 2001


You can't just redirect the pdf into the email, it will arrive as garbage. You
should MIME encode it.

#Program Locations
SENDMAIL=/usr/sbin/sendmail
MIMENCODE=/usr/bin/mimencode

FILE=/tmp/$$.pdf
SENDTO=$USER #Depends on which LPR daemon
FROM=PS2PDF
SUBJECT="New PDF Document"

# Check to see if pdf file was created
if [ -f $FILE ]; then
    if [ -n "$SENDTO" ]; then
	(MIMEBOUNDARY="NextPart$$"
	 echo "Mime-Version: 1.0"
	 echo "Content-Type: Multipart/Mixed; Boundary="$MIMEBOUNDARY""
	 echo "Content-Transfer-Encoding: 7bit"
	 echo "To: $SENDTO"
	 echo "From: $FROM"
	 echo "Subject: $SUBJECT"
	 echo ""
	 echo "--$MIMEBOUNDARY"
	 echo "Content-Type: text/plain; charset=us-ascii"
	 echo "Content-Transfer-Encoding: 7bit"
	 echo ""
	 echo ""
	 echo "--$MIMEBOUNDARY"
	 echo "Content-Type: application/pdf; name="$$.pdf""
	 echo "Content-Description: PDF document"
	 echo "Content-Transfer-Encoding: base64"
	 echo "Content-Disposition: attachment; filename="$$.pdf""
	 echo ""
	 $MIMENCODE $FILE 2>/dev/null
	 echo ""
	 echo "--$MIMEBOUNDARY--"
	) | 2>&1 $SENDMAIL -f$FROM -oi $SENDTO
    fi
else
    #
    # Generate notification mail for a failed attempt.
    #
    (echo "To: $SENDTO"
     echo "From: $FROM"
     echo "Subject: *ERROR* PDF Not created"
     echo ""
     echo "The PDF file was not created."
     echo ""
    ) | 2>&1 $SENDMAIL -f$FROM -oi $SENDTO
fi

> So the filter shouldn't be too difficult
>
>   #/bin/bash
>   #  Save the file.
>   cat > /tmp/$$.ps
>
>   #  Convert to PDF.
>   ps2pdf /tmp/$$.ps /tmp/$$.pdf
>
>   #  Mail the result.
>   mail < /tmp/$$.pdf ${USER}
>
>   #  Clean up.
>   rm -f /tmp/$$.ps /tmp/$$.pdf
>
> It will take some playing but it should work.
> --
> Jim
>
>




More information about the Kclug mailing list