home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / alt / sources / 2908 < prev    next >
Encoding:
Internet Message Format  |  1993-01-01  |  6.1 KB

  1. Path: sparky!uunet!wupost!emory!cs.utk.edu!cs.utk.edu!wade
  2. From: wade@cs.utk.edu (reed wade)
  3. Newsgroups: alt.sources
  4. Subject: Re: (Archivests will hate me!) Looking for USPS code
  5. Date: 1 Jan 1993 17:29:32 GMT
  6. Organization: Computer Science Dept, University of Tennessee, Knoxville
  7. Lines: 197
  8. Distribution: world
  9. Message-ID: <1i1v1sINNdc3@CS.UTK.EDU>
  10. References: <1hpkatINN154@spool.mu.edu>
  11. Reply-To: wade@cs.utk.edu (reed wade)
  12. NNTP-Posting-Host: austin.cs.utk.edu
  13.  
  14. In article <1hpkatINN154@spool.mu.edu>, marcr@studsys.mscs.mu.edu (Marc Rassbach) writes:
  15. |> Does anyone have any code out there that
  16. |> 
  17. |> 1- input a U.S.A. postal number
  18. |> 2- output a bar code
  19. |> 
  20. |> Thanks!
  21. |> 
  22. |> -- 
  23. |> Marc Rassbach    marcr@studsys.mscs.mu.edu    If you take my advice, that
  24. |> MS-DOS - it's not   marc@milestn.mil.wi.us    is your problem, not mine!
  25. |> my problem!     If it was said on UseNet, it must be true.
  26. |>    Unix - It's a nice place to live, but you don't want to visit there.
  27.  
  28. This was posted to comp.lang.postscript a little while ago--
  29.  
  30. --- Cut Here ---
  31. %!PS
  32.  
  33. % Postscript program to address a business-size envelope in accordance
  34. % with US Postal Service guidelines, including the 52-bit POSTNET barcode
  35. % Use of this program can help your mail arrive up to 2 days faster!
  36. % Note: A barcode will only be printed if the last word of the last line of
  37. %       the address is a 9-digit zipcode.
  38.  
  39. % by Tod McQuillin
  40. % tm8t+@andrew.cmu.edu
  41. % 10-Oct-1991
  42. % Copyright (C) 1991 Tod McQuillin
  43. % Revised 29-Oct-1992
  44. % This is version 1.1, incorporating patches courtesy of Brent Carruth
  45. % (BLCARR01@ulkyvx.louisville.edu)
  46.  
  47. % This program is free software; you can redistribute it and/or modify
  48. % it under the terms of the GNU General Public License as published by
  49. % the Free Software Foundation; either version 1, or (at your option)
  50. % any later version.
  51.  
  52. % This program is distributed in the hope that it will be useful,
  53. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  54. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  55. % GNU General Public License for more details.
  56.  
  57. /inch {72 mul} def
  58. /cm {inch 2.54 div} def
  59.  
  60. % LWIDTH and LHEIGHT define letter size paper.  The envelope will be printed
  61. % centered in this area, flush with the top of the page.  This works great
  62. % with a HP III printer; your mileage may vary
  63. /LWIDTH 8.5 inch def
  64. /LHEIGHT 11 inch def
  65.  
  66. % EHEIGHT and EWIDTH define the com10 size envelope.  They're supposed to be
  67. % 9.5 x 4.25 inches, but the ones I had were only 10.5 cm tall.  Change these
  68. % values to suit your envelopes -- the program will work with any envelopes
  69. % provided these values are set appropriately.
  70. /EHEIGHT 10.5 cm def
  71. /EWIDTH 9.5 inch def
  72.  
  73. /interline {            % define default leading
  74.   POINTSIZE 1.2 mul
  75.   } def
  76.  
  77. /fontset {              % fontname pointsize => -
  78.   exch findfont exch dup /POINTSIZE exch def scalefont setfont
  79.   } def
  80.  
  81. /defleading {           % define leading for nl
  82.   /LEADING interline def
  83.   } def
  84.  
  85. /nl {                   % print string and move to start of next line
  86.   dup stringwidth pop exch show neg LEADING neg rmoveto
  87.   } def
  88.  
  89. /addressfont {          % set font for address
  90.   /gillsans 14 fontset defleading
  91.   } def
  92.  
  93. /returnfont {           % set font for return address
  94.   /gillsans 12 fontset defleading
  95.   } def
  96.  
  97. /envelope {             % translate and rotate coordinate system to match com10
  98.   LWIDTH EHEIGHT sub 2 div EHEIGHT add LHEIGHT EWIDTH sub translate
  99.   90 rotate
  100.   0 3 32 div inch translate % fudge factor for my printer - change or remove
  101.   } def
  102.  
  103. /returnaddress {        % Print the return address
  104.   gsave
  105.     returnfont
  106.     % This positions the return address .25 inches from upper left of envelope
  107.     .25 inch EHEIGHT .25 inch sub POINTSIZE 3 64 div inch sub sub moveto
  108.     {nl} forall
  109.   grestore
  110.   } def
  111.  
  112. /address {              % Print the address
  113.   gsave
  114.     addressfont
  115.     4 inch 2.25 inch moveto     % Magic numbers conform to USPS guidelines
  116.     dup                         % save the address
  117.     {nl} forall
  118.     dup length 1 sub get        % Get the last line of the address
  119.     mark
  120.       { exch dup /str exch def  % Tokenise the line and save remainder in str
  121.         token not {exit} if
  122.     /barcodestring str def
  123.       } loop                    % Get the last word of the last line
  124.  
  125.     type cvlit /marktype ne {barcodestring barcode} if
  126.     cleartomark
  127.   grestore
  128.   } def
  129.  
  130. /barcodebits [          % From "A Guide to Business Mail Preparation"
  131.   (11000)       %0      % USPS Brochure/Pamphlet
  132.   (00011)       %1
  133.   (00101)       %2
  134.   (00110)       %3
  135.   (01001)       %4
  136.   (01010)       %5
  137.   (01100)       %6
  138.   (10001)       %7
  139.   (10010)       %8
  140.   (10100)       %9
  141.   ] def
  142.  
  143. /bit1 {                 % Draw a 1 bit of the POSTNET Barcode
  144.   0 .125 inch rlineto
  145.   1 inch 21 div .125 inch neg rmoveto
  146.   } bind def
  147.  
  148. /bit0 {                 % Draw a 0 bit of the POSTNET Barcode
  149.   0 .05 inch rlineto
  150.   1 inch 21 div .05 inch neg rmoveto
  151.   } bind def  
  152.  
  153. /dodigit {              % Do a complete digit of the barcode
  154.   barcodebits exch get {
  155.     2 mod 1 eq
  156.       {bit1}
  157.       {bit0}
  158.     ifelse
  159.     /BITS BITS 1 add def
  160.     } forall
  161.   } def
  162.  
  163. /barcode {              % Do a complete barcode
  164.   gsave
  165.     /CHECKSUM 0 def
  166.     /BITS 0 def
  167.     % More magic numbers to conform to USPS guidelines
  168.     EWIDTH 3.9375 inch sub .25 inch moveto
  169.     bit1
  170.       {
  171.       (0) 0 get sub dup dup 0 ge exch 9 le and {
  172.         dup /CHECKSUM exch CHECKSUM add def
  173.         dodigit
  174.         } if
  175.       } forall
  176.     CHECKSUM 10 mod neg 10 add dup 10 eq {pop 0} if
  177.     dodigit
  178.     bit1
  179.     BITS 50 eq {.02 inch setlinewidth stroke} if
  180. % if you want 5 digit zip codes barcoded as well, make the previous line be
  181. %   BITS 50 eq BITS 30 eq or {.02 inch setlinewidth stroke} if
  182. % I don't think it's a good idea to barcode a 5-digit zip.  Kinda defeats
  183. % the purpose.
  184.   grestore
  185.   } def
  186.  
  187. % Note that if you print your own barcode, you need not follow the address font
  188. % guidelines since the only use of the OCR machines is to print barcodes.
  189.   
  190. /tod [                  % That's me!
  191.   (Wade-Jones)
  192.   (2521 Greenfield Ln)
  193.   (Knoxville, TN)
  194.   (37912)
  195.   ] def
  196.  
  197. /addressee [
  198.   (Joe Random)
  199.   (123 Anystreet)
  200.   (Pittsburgh, PA  12111-1311)
  201.   ] def
  202.  
  203. envelope
  204. tod returnaddress
  205. addressee address
  206. showpage
  207.  
  208. %--- Cut Here ---
  209.  
  210.  
  211.