home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!emory!cs.utk.edu!cs.utk.edu!wade
- From: wade@cs.utk.edu (reed wade)
- Newsgroups: alt.sources
- Subject: Re: (Archivests will hate me!) Looking for USPS code
- Date: 1 Jan 1993 17:29:32 GMT
- Organization: Computer Science Dept, University of Tennessee, Knoxville
- Lines: 197
- Distribution: world
- Message-ID: <1i1v1sINNdc3@CS.UTK.EDU>
- References: <1hpkatINN154@spool.mu.edu>
- Reply-To: wade@cs.utk.edu (reed wade)
- NNTP-Posting-Host: austin.cs.utk.edu
-
- In article <1hpkatINN154@spool.mu.edu>, marcr@studsys.mscs.mu.edu (Marc Rassbach) writes:
- |> Does anyone have any code out there that
- |>
- |> 1- input a U.S.A. postal number
- |> 2- output a bar code
- |>
- |> Thanks!
- |>
- |> --
- |> Marc Rassbach marcr@studsys.mscs.mu.edu If you take my advice, that
- |> MS-DOS - it's not marc@milestn.mil.wi.us is your problem, not mine!
- |> my problem! If it was said on UseNet, it must be true.
- |> Unix - It's a nice place to live, but you don't want to visit there.
-
- This was posted to comp.lang.postscript a little while ago--
-
- --- Cut Here ---
- %!PS
-
- % Postscript program to address a business-size envelope in accordance
- % with US Postal Service guidelines, including the 52-bit POSTNET barcode
- % Use of this program can help your mail arrive up to 2 days faster!
- % Note: A barcode will only be printed if the last word of the last line of
- % the address is a 9-digit zipcode.
-
- % by Tod McQuillin
- % tm8t+@andrew.cmu.edu
- % 10-Oct-1991
- % Copyright (C) 1991 Tod McQuillin
- % Revised 29-Oct-1992
- % This is version 1.1, incorporating patches courtesy of Brent Carruth
- % (BLCARR01@ulkyvx.louisville.edu)
-
- % 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 1, 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 for more details.
-
- /inch {72 mul} def
- /cm {inch 2.54 div} def
-
- % LWIDTH and LHEIGHT define letter size paper. The envelope will be printed
- % centered in this area, flush with the top of the page. This works great
- % with a HP III printer; your mileage may vary
- /LWIDTH 8.5 inch def
- /LHEIGHT 11 inch def
-
- % EHEIGHT and EWIDTH define the com10 size envelope. They're supposed to be
- % 9.5 x 4.25 inches, but the ones I had were only 10.5 cm tall. Change these
- % values to suit your envelopes -- the program will work with any envelopes
- % provided these values are set appropriately.
- /EHEIGHT 10.5 cm def
- /EWIDTH 9.5 inch def
-
- /interline { % define default leading
- POINTSIZE 1.2 mul
- } def
-
- /fontset { % fontname pointsize => -
- exch findfont exch dup /POINTSIZE exch def scalefont setfont
- } def
-
- /defleading { % define leading for nl
- /LEADING interline def
- } def
-
- /nl { % print string and move to start of next line
- dup stringwidth pop exch show neg LEADING neg rmoveto
- } def
-
- /addressfont { % set font for address
- /gillsans 14 fontset defleading
- } def
-
- /returnfont { % set font for return address
- /gillsans 12 fontset defleading
- } def
-
- /envelope { % translate and rotate coordinate system to match com10
- LWIDTH EHEIGHT sub 2 div EHEIGHT add LHEIGHT EWIDTH sub translate
- 90 rotate
- 0 3 32 div inch translate % fudge factor for my printer - change or remove
- } def
-
- /returnaddress { % Print the return address
- gsave
- returnfont
- % This positions the return address .25 inches from upper left of envelope
- .25 inch EHEIGHT .25 inch sub POINTSIZE 3 64 div inch sub sub moveto
- {nl} forall
- grestore
- } def
-
- /address { % Print the address
- gsave
- addressfont
- 4 inch 2.25 inch moveto % Magic numbers conform to USPS guidelines
- dup % save the address
- {nl} forall
- dup length 1 sub get % Get the last line of the address
- mark
- { exch dup /str exch def % Tokenise the line and save remainder in str
- token not {exit} if
- /barcodestring str def
- } loop % Get the last word of the last line
-
- type cvlit /marktype ne {barcodestring barcode} if
- cleartomark
- grestore
- } def
-
- /barcodebits [ % From "A Guide to Business Mail Preparation"
- (11000) %0 % USPS Brochure/Pamphlet
- (00011) %1
- (00101) %2
- (00110) %3
- (01001) %4
- (01010) %5
- (01100) %6
- (10001) %7
- (10010) %8
- (10100) %9
- ] def
-
- /bit1 { % Draw a 1 bit of the POSTNET Barcode
- 0 .125 inch rlineto
- 1 inch 21 div .125 inch neg rmoveto
- } bind def
-
- /bit0 { % Draw a 0 bit of the POSTNET Barcode
- 0 .05 inch rlineto
- 1 inch 21 div .05 inch neg rmoveto
- } bind def
-
- /dodigit { % Do a complete digit of the barcode
- barcodebits exch get {
- 2 mod 1 eq
- {bit1}
- {bit0}
- ifelse
- /BITS BITS 1 add def
- } forall
- } def
-
- /barcode { % Do a complete barcode
- gsave
- /CHECKSUM 0 def
- /BITS 0 def
- % More magic numbers to conform to USPS guidelines
- EWIDTH 3.9375 inch sub .25 inch moveto
- bit1
- {
- (0) 0 get sub dup dup 0 ge exch 9 le and {
- dup /CHECKSUM exch CHECKSUM add def
- dodigit
- } if
- } forall
- CHECKSUM 10 mod neg 10 add dup 10 eq {pop 0} if
- dodigit
- bit1
- BITS 50 eq {.02 inch setlinewidth stroke} if
- % if you want 5 digit zip codes barcoded as well, make the previous line be
- % BITS 50 eq BITS 30 eq or {.02 inch setlinewidth stroke} if
- % I don't think it's a good idea to barcode a 5-digit zip. Kinda defeats
- % the purpose.
- grestore
- } def
-
- % Note that if you print your own barcode, you need not follow the address font
- % guidelines since the only use of the OCR machines is to print barcodes.
-
- /tod [ % That's me!
- (Wade-Jones)
- (2521 Greenfield Ln)
- (Knoxville, TN)
- (37912)
- ] def
-
- /addressee [
- (Joe Random)
- (123 Anystreet)
- (Pittsburgh, PA 12111-1311)
- ] def
-
- envelope
- tod returnaddress
- addressee address
- showpage
-
- %--- Cut Here ---
-
-
-