Royalty-free developer license, one time purchase for lifetime use
OneCode Barcode Introduction
OneCode is also known as OneCode 4CB, USPS 4CB, 4-CB, 4-State Customer Barcode, USPS OneCode Solution Barcode.
OneCode 4-State Customer Barcode (4-CB) is the next generation in the evolution of USPS barcode technology. It does not replace existing barcodes - it offers a more effective alternative. Partnering with the Mailing Industry, the Postal Service developed the 4-CB which increases the amount of information carried on letter and flats mail pieces and allows for expanded tracking capability, creating greater visibility into the mailstream.
4-CB is a height-modulated barcode using four distinct, vertical bar types. It encodes a 31-digit string into 65 vertical bars each representing one of four possible states: full bar, ascender, tracker, and descender.
4-State Barcode Bars
4-CB carries a payload 31 digits comprised of the following elements.
2 (2nd digit must be 0-4)
Service Type Identifier
6 or 9
9 or 6
If Mailer Identifier is 6, Serial Number must be 9.
If Mailer Identifier is 9, Serial Number must be 6.
Delivery Point ZIP Code
0, 5, 9, or 11
Table 1 - USPS OneCode SOLUTION Barcode Data Fields
For each of the fields in Table 1, except the Routing Code, leading or trailing zeros shall be provided to achieve the correct size. Spaces and nulls are not acceptable characters for padding. For ZIP Codes, which have one of four lengths, encoding shall provide padding beyond the digits to be encoded. No error detection and correction, such as a checksum with POSTNET or PLANET, shall be included as part of the data fields. The OneCode Barcode Data Fields are described as follows:
The Barcode Identifier is assigned by USPS for the type of tracking service. This is two digits, with the second digit in the range of 0-4.
The Service Type Identifier is assigned by USPS for any special services on the mailpiece. The allowable encoding range is 000-999.
The Mailer Identifier is assigned by USPS as a unique identifier for each OneCode SOLUTION customer. The allowable encoding range is 000000-99999.
The Serial Number is assigned by the mailer for tracking mailpieces. The allowable encoding range is 000000000-999999999.
The Delivery Point ZIP Code is assigned by the mailer for routing the mailpiece. This replaces POSTNET for routing the mailpiece to its final delivery point. The length may be 0, 5, 9, or 11 digits. The allowable encoding ranges are no ZIP Code, 00000-99999, 000000000-999999999, and 00000000000-99999999999.
OneCode Encoding Data Scope
Onecode Barcode for Java supports:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
How to Generate USPS OneCode Barcode in Java Class?
The following Java code illustrates how to create a OneCode barcode, and output to various formats.
1 Linear linear = new Linear(); 2 linear.setType(Linear.ONECODE); 3 linear.setData("34160265194042788110"); 4 linear.renderBarcode("c:/barcode.gif");
Under java_barcode_trial package, copy barcode folder to your java servlet container like tomcat.
Restart tomcat. Now you have installed successfully.
To test your installation, open your web browser and navigate to: http://YourDomain:Port/barcode/linear?Data=34160265194042788110&Type=ONECODE
To create barcode image in your JSP or html page, you need pass the url to IMG tag src value. For example, <img src="http://YourDomain:Port/barcode/linear?Data=34160265194042788110&Type=ONECODE" /> Using this method, it will not generate any barcode images in your server side.
The second method is to generate barcode images in your server side.
Create a barcode image in server side, like Linear linear = new Linear(); linear.setData("34160265194042788110"); linear.setType(Linear.ONECODE); linear.renderBarcode("C:/Tools/Tomcat 5.5/webapps/YourWebApp/barcode-images/barcode.gif");
In your JSP or HTML page, you need use IMG tag to display generated image, like <img src="http://YourDomain:Port/YourWebApp/barcode-images/barcode.gif" />
How to Generate Barcode USPS OneCode Image in Jasper Reports, iReport, Eclipse BIRT?
Set the type property to Linear.ONECODE Servlet URL Parameter: "Type". Value: 36. Sample: &Type=36.
Set the data property with the value to encode. Type is String. Servlet URL Parameter: Data.
Valid Data Scope:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Valid Data Format:
The valid data length should be 20, 25, 29, or 31 digits.
addCheckSum property is not applied.
Barcode image size settings.
Set property uom (Unit of Measure) for properties X, Y, leftMargin, rightMargin, topMargin and bottomMargin. Default is Linear.UOM_PIXEL (0). Valid values are Linear.UOM_PIXEL (0), Linear.UOM_CM (1), Linear.UOM_Inch (2). Servlet URL Parameter: "UOM". Value: 0 (pixel), 1 (cm), 2 (inch). Sample: &UOM=0.
Set the X (for barcode module width) and Y (for barcode module height) properties. Both types are float. Default X is 3. Y is 75. Servlet URL Parameter: "X", "Y". Sample: &X=3&Y=75.
Set the leftMargin, rightMargin, topMargin and bottomMargin properties, and types are all float. Default values are 0 for all 4 margin settings. Servlet URL Parameter: "LeftMargin", "RightMargin", "TopMargin", "BottomMargin". Sample: &LeftMargin=0.
Set the resolution property (Value is expressed in DPI - Dots per inch). Default is 72 dpi. Servlet URL Parameter: "Resolution". Sample: &Resolution=72.
Setting up text style in barcode image.
Set the showText properties. If this value is true, barcode data will be displayed with the barcode. Default is true. Servlet URL Parameter: "ShowText". Value: "t" (true), "f" (false). Sample: &ShowText=t.
Set the textFont property. The font used to display text in barcode image. Default is new Font("Arial", Font.PLAIN, 11). Servlet URL Parameter: "TextFont". Value format: [font name]|[font style]|[font size]. Sample Values: &TextFont=Arial|Bold|12
With rotate property, you can display barcode horizontally or vertically. Default value is 0. Servlet URL Parameter: "Rotate". Sample: &Rotate=0. Value can be: