POSTNET barcodes
Informations
Author: Shailesh Humbad
License: FPDF
Description
This is an extension for printing U.S. Postal Service POSTNET barcodes in PDF. It
supports both 5 and 9 digit zip codes and includes a utility function for parsing zip
codes from an address line. The barcode is drawn directly in PDF without using an image
or special font.
POSTNETBarCode(float x, float y, string zipcode)
x
: abscissa of barcode
y
: ordinate of barcode
zipcode
: zip code to draw
$zipcode must be a string containing a zip code of the form DDDDD or DDDDD-DDDD. This function
will trigger a PHP error if the zip code is invalid, so if the string's validity is in question,
use ParseZipCode first. The parameters $x and $y specify the lower left corner of the barcode
in user units. This function changes the line width in the FPDF context.
string ParseZipCode(string stringToParse)
The parsed zip code returned will be the first string matching DDDDD or DDDDD-DDDD, in that
order, where D is a digit from 0 through 9. The search begins at the end of $stringToParse.
If a valid zip code cannot be found, it returns an empty string. Otherwise, it returns the
parsed zip code (including the hyphen if it's a 9-digit zip).
An online example is available
here.
POSTNET BARCODES
The specifications for POSTNET Barcodes can be found in U.S. Postal Service Publication
25, Designing Letter and Reply Mail. See Chapter 2 for barcode placement specifications,
and Chapter 4 for barcode reading and writing specifications.
You can print barcodes on papers that will be inserted into envelopes with windows, or
directly on envelopes. For envelopes with windows, in general, the barcode should be
printed a minimum of 1/25" above the first line of the address, and below the top edge of
the envelope window. The left and right clearance for the address should be a minimum of
1/8", and the bottom clearance should be 1/25" minimum. The address must satisfy the
minimum clearances regardless of where the mailpiece shifts to within the envelope.
Note that 1/4" of clearance is preferred.
Refer to the Guidelines for complete details.