Newsgroups: comp.text.desktop
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!cornell!uw-beaver!fluke!dcd
From: dcd@tc.fluke.COM (David Dyck)
Subject: Re: PostNet Barcodes
Message-ID: <1991Apr29.185533.16365@tc.fluke.COM>
Summary: USPS BARCODE
Keywords: postnet postscript envelope address barcode
Organization: John Fluke Mfg. Co., Inc., Everett, WA
References: <1991Apr24.011358.322@mac.cc.macalstr.edu> <1991Apr27.190905.23979@tc.fluke.COM> <73508@eerie.acsu.Buffalo.EDU>
Date: Mon, 29 Apr 91 18:55:33 GMT

I have had several requests to post the postscript program.
This is what I received in comp.lang.postscript last May.

>From: woody@chinacat.Unicom.COM (Woody Baker @ Eagle Signal)
Subject: Re:US POSTAL BARCODE
Message-ID: <1253@chinacat.Unicom.COM>
Date: 21 May 90 04:28:33 GMT
Organization: a guest of Unicom Systems Development, Austin

During the trade show, that I did the airplane for, I ran across the
United States Postoffice booth.  They were giving out free, nifty
holographic stamed envelopes.  These are FANTASTIC!  They have been on
sale since Dec.  The envelope cost is .05 and the postage cost is
.25 for a total cost of .30.  Go to your nearest post office and buy
one!  Earlier, I had spent about an hour "cracking" the USPS bar code
printed at the bottom of prepaid mailer cards.  A call to the Postoffice
as to how to compute the check digit did not yeild any usefull info.  The
lady at the show booth however, sent me publication 25, A Guide to Business
Mail Preparation, along with a nifty transparent template.  I got it, and
immediatly created the following program (something that I have wanted
for a long time.)  Bulk mailers get cheaper rates for presorted by zipcode,
and presumable the bar code will give you a better rate as well. (I have not
verified this.)  So, here is the barcode printer, as well as an address
positioner that meets USPS policy.

Enjoy
Cheers
Woody


%
%
% (C) Copyright 1990 by Woody Baker
% Rt.1 Box I
% Manor, Tx. 78653
%
% this code may be used for personal use,  as long as this header
% remains intact but may not be used
% as part of a commercial package.  All commercial rights reserved.
%
%
% code to print usps barcode.
% checkdigit computation is the sum of the digits, rounded up to
% the next even multiple of 10.
%
% You MUST print this on the envelope within certain very specific areas.
% The x and y coordinate MUST have the following relationship with the
% RIGHT LOWER CORNER of the envelope.
% x can be no further from the right edge than 4" and no closer than
% 3 1/4.  The y coordinate MUST be 1/4 inch up from the bottom of the
% envelope, +/- 1/16 th inch.  The x coordinates' wide lea-way is
% to accomodate shifting of inserts containing POSTNET codes which appear
% through windows in the envelope.  For printed barcodes on envelopes
% the post office prefers 3 7/8 to 4 inches.
% request Publication 25 (A Guide to Business Mail Preparation) from
% your local Post Office.  Be sure to ask for the template that accompanies
% the book.
%
/inches {72 mul} def
/barwidth .020 inches def	% MUST NOT CHANGE
/long  .125 inches def		% MUST NOT CHANGE
/short .050 inches def		% MUST NOT CHANGE
/nextx .0475 inches def		% MUST NOT CHANGE
%
% one of the recommended fonts for OCR lables.  10/14 is one of the
% recommended settings.
%
/Helvetica findfont 10 scalefont setfont
/linehite 14 def
%
/digarray
	[
	{
	lbar lbar sbar sbar sbar 	% digit 0
	}	
	{
	sbar sbar sbar lbar lbar 	% digit 0
	}
	{
	sbar sbar lbar sbar lbar 	% digit 2
	}
	{
	sbar sbar lbar lbar sbar 	% digit 3
	}
	{
	sbar lbar sbar sbar lbar 	% digit 4
	}
	{
	sbar lbar sbar lbar sbar 	% digit 5
	}
	{
	sbar lbar lbar sbar sbar 	% digit 6
	}
	{
	lbar sbar sbar sbar lbar 	% digit 7
	}
	{
	lbar sbar sbar lbar sbar 	% digit 8
	}
	{
	lbar sbar lbar sbar sbar 	% digit 9
	}
	] def

%
% sbar does a short bar, and alters the current point accordingly
%
%
/sbar
	{
	barwidth setlinewidth		% always make sure it is correct width
	currentpoint			% remember where we are
	currentpoint short add lineto	% do the bar
	exch nextx add exch moveto	% advance the current point
	} def
%	
% lbar does a tall bar and alters the current point accordingly
%
/lbar
	{
	barwidth setlinewidth		% always make sure it is correct width
	currentpoint			% remember where we are
	currentpoint long add lineto	% do the bar
	exch nextx add exch moveto	% advance the current point
	} def
%
% routine takes a string of numbers (no hyphens in the first cut)
% an orientation flag (1=Landscape) and an x and y coordinate
%
%
% x y orientation (numberstring)
%
% check digit computation 10 sum 10 mod sub computes the remainder
% from a divide by 10, and then subtracts that from 10 to generate
% a digit, which if added back to sum would round it up to the next even 
% multiple of 10
%

/dobar
{
	/msg exch def	% get all parameters from the stack.
	/orient exch def
	 moveto % relative to origin of mail piece
	/sum 0 def
	
	gsave
	 	orient 1 eq
	 		{
	 		90 rotate 0 -612 translate
	 		} if
		lbar		 % starting marker
		msg		 % process the message.
			{
			48 sub dup		% convert the digit to binary
			sum add /sum exch def	% update the checksum
			/digval exch def	% have the binary digit
			digarray digval get  exec % draw the digit.
			}
		forall
		digarray
		10 sum 10 mod sub		% compute check digit	
		get exec
		lbar				% ending marker
		stroke
	grestore
} def	

%
% routine takes x y array of strings and does an address block
% for an envelope.  Prefered is ALL UPPERCASE
% [(WOODY BAKER) (RR 1 BOX I) (MANOR  TX  78653)]
% NOTE: the City State and Zip MUST be the last line, and in that order.
% it is preferable NOT to use punctuation.  If the last line won't fit, it
% is permitted to put the ZIPCODE on the line under that, all by itself.
% you should provide that decision, when constructing the array of strings.
%
% In addition, since this is HELVETICA, and it is Proportional, it
% is a wise idea to put 2 spaces down rather than 1 for separation.  The
% USPS states that there should be at least 1 full space or 1 em space
% between the characters, and at least 2 points additional 
% leading between the lines, 4 points is better for a 10 pt font.
%
% bottom line of RETURN address no lower that 2 3/4" from bottom edge
% of envelope. Mailto address should fit  within a rectangle that extends
% from 5/8 " from the bottom, to 2 1/4" up from the bottom of the mail piece.

%
/address
	{
	/stringaray exch def
	/ycoord exch def
	/xcoord exch def
	xcoord
	stringaray length		% get number of lines
	linehite mul ycoord add moveto	% adaptively find the top line.
	stringaray
		{
		currentpoint linehite sub exch pop xcoord exch moveto
		show
		} forall
	} def
%
% example code for testing
%
100 120 [(WOODY  BAKER) (RR 1  BOX I) (MANOR  TX  78653-0102)] address
100 100 0 (786530102) dobar
200 200 1 (1234567890) dobar
showpage
