From: sham@cs.arizona.edu (Shamim Zvonko Mohamed) Newsgroups: comp.lang.postscript Subject: Re: Zip Code "Bar Codes" Date: 30 Oct 92 18:31:53 GMT Organization: U of Arizona CS Dept, Tucson I have this script that generates PS for envelopes, including the FIM and 5-digit zips. It also typesets the address in accordance with the USPS guideline (Ref. "A Guide to Business Mail Preparation"). It also prints return addresses, and can accommodate different envelope sizes. It's short enough that I guess it can be posted here, so here goes: ==================== cut here ================= : # Copyright 1991 Shamim P. Mohamed # Department of Computer Science, University of Arizona, Tucson AZ 85721 # # * This program is free software; you can redistribute it and/or modify # * it under the terms of the GNU General Public License as published by # * the Free Software Foundation; either version 2 of the License, or # * (at your option) any later version. # * # * This program is distributed in the hope that it will be useful, # * but WITHOUT ANY WARRANTY; without even the implied warranty of # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # * GNU General Public License (the file COPYING in this directory, or send # * me mail) for more details. # * # # Usage: # The addresses are read from standard input. The adressee's address comes # first, and a '#' alone on a line demarcates the to address and the sender's # address. # # $ pr-envelope [-c] [width height] | lpr # Acme Products # 1 Gizmo Drive # Olmo, RI 02345-8956 # # # Wile E. Coyote # 10 Hunger Drive # Toon Town, NV 56789-1234 # # The return address is optional; if not present, it will look for the file # $HOME/.return_address and use that; and if that is missing, no return # address will be printed. If the +4 is missing, it will print a 5-digit # bar-code. If the zip is missing, the Postnet bar-code will not be printed, # and neither will the FIM (the mark at the top that indicates that a bar-code # is present, and the orientation). The address will be converted to all # upper-case, except if -c is used. Punctuation is removed. # (Ref. "A Guide to Business Mail Preparation," USPS Publication.) # # Arguments are size of the envelope (in PostScript units, 72 = 1 inch), and # default to the standard business size. The envelope should be manually fed, # centered. This works on LaserWriters, you may have to experiment a little # for other printers. # if [ ."$1" = '.-?' ]; then echo Usage: $0 '[-c] [width height] | lpr' exit 1 fi if [ ."$1" = .-c ]; then echo Preserving case. >&2 case_cmd=cat shift; else case_cmd="tr a-z A-Z" fi e_width="${1:-678}" e_height="${2:-298}" echo Using size $e_width x $e_height >&2 $case_cmd | sed -e 's/\.//g;s/,//g;s/ */ /g' | awk ' BEGIN { FS = " "; zip = ""; print "%!\n/nopostnet 0 def /addr [" } length > 1 { printf "(%s)\n", $0 } { z = $NF } length == 1 { if($0 == "#") {zip = substr(z,1,5)+0; p4 = substr(z,7,4)+0 print "] def /rt ["} else { printf "(%s)\n", $0 }} END { if(zip == "") {zip = substr(z,1,5)+0; p4 = substr(z,7,4)+0} if(zip == 0) print "] def /nopostnet 1 def"; else if(p4 == 0) printf "] def /zip4 (%05.5d) def\n", zip; else printf "] def /zip4 (%05.5d%04.4d) def\n", zip, p4 }' | sed -e 's/ / /g' if [ -f $HOME/.return_address ]; then echo /dfl_rt '[' awk '{print "(" $0 ")"}' <$HOME/.return_address echo '] def' else echo /dfl_rt '[()] def' fi cat << END_OF_PS /in {72 mul} def /mm {2.83 mul} def /cm {28.3 mul} def /xdisp 792 0.56 $e_width mul sub def /ydisp 306.0 $e_height 2 div sub def newpath clippath pathbbox pop exch pop add 0 translate 90 rotate newpath .010 in setlinewidth /l_one .125 in def /l_zero .050 in def /bar_spacing .0475 in def /Helvetica findfont 10 scalefont setfont /linehite {14} def /barcode [ (11000) (00011) (00101) (00110) (01001) (01010) (01100) (10001) (10010) (10100) ] def /zero { 0 l_zero rlineto bar_spacing l_zero neg rmoveto } def /one { 0 l_one rlineto bar_spacing l_one neg rmoveto } def /do_barcode { moveto /sum 0 def gsave one { 48 sub dup sum add /sum exch def barcode exch get {48 eq {zero}{one} ifelse} forall } forall barcode 90 sum sub 10 mod get {48 eq {zero}{one} ifelse} forall one stroke grestore } def /height 0.625 in def /thick 0.7 mm def /sm_space 1.6 mm def /lg_space 4.5 mm def /orientmark { moveto gsave thick setlinewidth 0 height rlineto sm_space 0 rmoveto 0 height neg rlineto lg_space 0 rmoveto 0 height rlineto lg_space 0 rmoveto 0 height neg rlineto sm_space 0 rmoveto 0 height rlineto stroke grestore } def /address { pstack /stringaray exch def /ycoord exch def /xcoord exch def xcoord stringaray length linehite mul ycoord add moveto stringaray { currentpoint linehite sub exch pop xcoord exch moveto show } forall } def /address2 { /x currentpoint pop def { x currentpoint linehite sub exch pop moveto show } forall } def xdisp ydisp 100 add addr address nopostnet 0 eq { zip4 510 ydisp 18 add do_barcode 612 300 $e_height 2 div add height sub orientmark } if /Bookman-Light findfont 8 scalefont setfont /linehite {9} def 815 $e_width sub 293 $e_height 2 div add moveto userdict /rt known {rt} {dfl_rt} ifelse address2 showpage END_OF_PS exit 0 ===================== cut here ================ -- Shamim Mohamed / {uunet,noao,cmcl2..}!arizona!shamim / shamim@cs.arizona.edu "Take this cross and garlic; here's a Mezuzah if he's Jewish; a page of the Koran if he's a Muslim; and if he's a Zen Buddhist, you're on your own." Member of the League for Programming Freedom - write to league@prep.ai.mit.edu