From nelson@sun.soe.clarkson.edu Mon Apr  5 11:44:29 1993
Newsgroups: comp.sources.postscript
From: nelson@sun.soe.clarkson.edu (Russ Nelson)
Subject: v01i056: postal - Envelope address, with postal bar code, Part01/01
Followup-To: comp.sources.d
Summary: Prints the mailing address, return address, and bar code for snail mail
Reply-To: nelson@sun.soe.clarkson.edu (Russ Nelson)
Organization: Clarkson University, Potsdam NY
Date: Mon, 5 Apr 1993 16:08:15 GMT

Submitted-by: nelson@sun.soe.clarkson.edu (Russ Nelson)
Posting-number: Volume 01, Issue 56
Archive-name: postal/part01
Environment: PostScript
Keywords: envelope, address, bar code, mail

[ Here is a repost of an old comp.lang.postscript posting. -Jon ]

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# Contents:  postal.ps
# Wrapped by jgm@monaco on Mon Apr  5 11:01:41 1993
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
echo If this archive is complete, you will see the following message:
echo '          "shar: End of archive."'
if test -f 'postal.ps' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'postal.ps'\"
else
  echo shar: Extracting \"'postal.ps'\" \(4765 characters\)
  sed "s/^X//" >'postal.ps' <<'END_OF_FILE'
X%!PS
X
X% Postscript program to address a business-size envelope in accordance
X% with US Postal Service guidelines, including the 52-bit POSTNET barcode.
X% Use of this program can help your mail arrive up to 2 days faster!
X% Note: A barcode will only be printed if the last word of the last line of
X% 	the address is a 9-digit zipcode.
X
X% by Tod McQuillin
X% tm1d@nike.cheme.cmu.edu
X% 10-Oct-1991
X% Copyright (C) 1991 Tod McQuillin
X
X% This program is free software; you can redistribute it and/or modify
X% it under the terms of the GNU General Public License as published by
X% the Free Software Foundation; either version 1, or (at your option)
X% any later version.
X
X% This program is distributed in the hope that it will be useful,
X% but WITHOUT ANY WARRANTY; without even the implied warranty of
X% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
X% GNU General Public License for more details.
X
X/inch {72 mul} def
X/cm {inch 2.54 div} def
X
X% LWIDTH and LHEIGHT define letter size paper.  The envelope will be printed
X% centered in this area, flush with the top of the page.  This works great
X% with a HP III printer; your mileage may vary
X/LWIDTH 8.5 inch def
X/LHEIGHT 11 inch def
X
X% EHEIGHT and EWIDTH define the com10 size envelope.  They're supposed to be
X% 9.5 x 4.25 inches, but the ones I had were only 10.5 cm tall.  Change these
X% values to suit your envelopes -- the program will work with any envelopes
X% provided these values are set appropriately.
X/EHEIGHT 10.5 cm def
X/EWIDTH 9.5 inch def
X
X/interline {	 	% define default leading
X  POINTSIZE 1.2 mul
X  } def
X
X/fontset {		% fontname pointsize => -
X  exch findfont exch dup /POINTSIZE exch def scalefont setfont
X  } def
X
X/defleading {		% define leading for nl
X  /LEADING interline def
X  } def
X
X/nl {			% print string and move to start of next line
X  dup stringwidth pop exch show neg LEADING neg rmoveto
X  } def
X
X/addressfont {		% set font for address
X  /Helvetica 16 fontset defleading
X  } def
X
X/returnfont {		% set font for return address
X  /Helvetica 12 fontset defleading
X  } def
X
X/envelope {		% translate and rotate coordinate system to match com10
X  LWIDTH EHEIGHT sub 2 div EHEIGHT add LHEIGHT EWIDTH sub translate
X  90 rotate
X  0 3 32 div inch translate % fudge factor for my printer - change or remove
X  } def
X
X/returnaddress {	% Print the return address
X  gsave
X    returnfont
X    % This positions the return address .25 inches from upper left of envelope
X    .25 inch EHEIGHT .25 inch sub POINTSIZE 3 64 div inch sub sub moveto
X    {nl} forall
X  grestore
X  } def
X
X/address {		% Print the address
X  gsave
X    addressfont
X    4 inch 2.25 inch moveto	% Magic numbers conform to USPS guidelines
X    dup				% save the address
X    {nl} forall
X    dup length 1 sub get	% Get the last line of the address
X    mark
X      {
X        exch token not {exit} if
X      } loop		      	% Get the last word of the last line
X    dup
X    /str 20 string def
X    type cvlit /marktype ne {str cvs barcode} if
X    cleartomark
X  grestore
X  } def
X
X/barcodebits [		% From "A Guide to Business Mail Preparation"
X  (11000)	%0	% USPS Brochure/Pamphlet
X  (00011)	%1
X  (00101)	%2
X  (00110)	%3
X  (01001)	%4
X  (01010)	%5
X  (01100)	%6
X  (10001)	%7
X  (10010)	%8
X  (10100)	%9
X  ] def
X
X/bit1 {			% Draw a 1 bit of the POSTNET Barcode
X  0 .125 inch rlineto
X  1 inch 21 div .125 inch neg rmoveto
X  } bind def
X
X/bit0 {	 		% Draw a 0 bit of the POSTNET Barcode
X  0 .05 inch rlineto
X  1 inch 21 div .05 inch neg rmoveto
X  } bind def  
X
X/dodigit {    		% Do a complete digit of the barcode
X  barcodebits exch get {
X    2 mod 1 eq
X      {bit1}
X      {bit0}
X    ifelse
X    /BITS BITS 1 add def
X    } forall
X  } def
X
X/barcode {		% Do a complete barcode
X  gsave
X    /CHECKSUM 0 def
X    /BITS 0 def
X    % More magic numbers to conform to USPS guidelines
X    EWIDTH 3.9375 inch sub .25 inch moveto
X    bit1
X      {
X      (0) 0 get sub dup dup 0 ge exch 9 le and {
X        dup /CHECKSUM exch CHECKSUM add def
X	dodigit
X	} if
X      } forall
X    CHECKSUM 10 mod neg 10 add dup 10 eq {pop 0} if
X    dodigit
X    bit1
X    BITS 50 eq {.02 inch setlinewidth stroke} if
X% if you want 5 digit zip codes barcoded as well, make the previous line be
X%   BITS 50 eq BITS 30 eq or {.02 inch setlinewidth stroke} if
X% I don't think it's a good idea to barcode a 5-digit zip.  Kinda defeats
X% the purpose.
X  grestore
X  } def
X
X% Note that if you print your own barcode, you need not follow the address font
X% guidelines since the only use of the OCR machines is to print barcodes.
X  
X/tod [			% That's me!
X  (Tod N. McQuillin)
X  (25 Dilworth Street)
X  (Apartment 2)
X  (Pittsburgh, PA 15211-1913)
X  ] def
X
X/addressee [
X  (J. Random Loser)
X  (1234 Anystreet Blvd)
X  (Anytown, NY 10001-1234)
X  ] def
X
Xenvelope
Xtod returnaddress
Xaddressee address
Xshowpage
END_OF_FILE
  if test 4765 -ne `wc -c <'postal.ps'`; then
    echo shar: \"'postal.ps'\" unpacked with wrong size!
  fi
  # end of 'postal.ps'
fi
echo shar: End of archive.
exit 0

