Contents
Introduction
Sample application
Maxicode class
MaxicodeControl class
MaxicodeWebControl class
References
Introduction
The package RMaxicode contains the classes you need to create Maxicode
barcodes within your .NET applications. It has been developed using
c# however it can also be used with other .NET languages as vb.net.
Maxicode is a two-dimensional (2D) and fixed-size matrix symbology
which is made up of offset rows of hexagonal modules arranged around
a unique finder pattern. The size of Maxicode is 1.11 x 1.054 inches
and it can contain up to 93 data characters of information (a total
of 144 including error correction codewords).
The symbol was created by United Parcel Service for fast scanning
and sorting of packages.RMaxicode supports the following features:
- modes 2,3,4,5 and 6.
- structured append
- full character set.

Symbol structure
MaxiCode symbols are divided into a primary and a secondary message,
each of which contains data and error correction codewords. The primary
message is made of 10 codewords and 10 error correction codewords. The
primary message is used in mode 2 and 3 to encode the Postal Code, the
Service class and the country.
Error correction
MaxiCode symbols have error correction codewords, based on Reed-Solomon
error correction algorithms, which can be used to detect errors and
correct erroneous symbols. There are two error levels; standard and
enhanced (mode 5).
Maxicode modes
Modes 2 and 3 are designed for use in the transport industry. They
encode the destination address and the class of service as defined by
the carrier. Mode 2 uses a 9 digit numeric postal code and mode 3 uses
a 6 character alphanumeric postal code. The Service class and the country
are both a 3 digit number in both modes.
Mode 4 can encode up to 93 characters or 138 digits. Mode 5 can only
encode up to 77 characters but it provides more error correction capabilities
(enhanced mode) than mode 4.
Mode 6 indicates that the symbol encodes a message used to program
the reader system (scanner).
Structured append
Up to eight MaxiCode symbols may be appended in a structured format.
This allows files of data to be represented in up to 8 MaxiCode symbols.
Sample application
In order to run the sample application you must execute MaxicodeTest10.exe
or MaxicodeTest11.exe.

In the sample application you can set following properties:
- Mode to be used
- Printer resolution (dots per inch).
- Service class, Country and Postal code (for modes 2 and 3).
- Data to be encoded.
- Number of symbols in the secuence (if you use structured append)
- Position of the symbol within the secuence.
and execute the following command:
- Apply: repaint the symbol using the new properties.
- Print: print using the given resolution.
- Save: save the symbol in GIF format using the given resolution.
Note: Tilde Processing: You can use the
format ~ddd if you want to specify the ascii code of the character
to be encoded. For example, if you enter the following text in the Data
field:
~066AA
you will actually be encoding
BAA
because ~066 will be replaced with the character ascii character 66,
which is B. You must use ~~ in order to encode the ~ character. If you
want to deactivate this behaviour you must call the method setProcessTilde(false).
RMaxicode class
The main class for creating rmaxicode barcodes is J4L.RMaxicode.RMaxicode.
The following methods allows you to configurate the barcode:
- public void setMode(int m): maxicode mode. Values range from
2 to 6
- public void setZipCode(string zp):postal code (modes 2 and
3)
- public void setServiceClass(string s): service class (modes
2 and 3). In mode 2 it can be an alphanumeric of length 5. In mode
3 can be a numeric of length 9.
- public void setCountry(string c): country code (modes 2 and
3)
- public void setData(string d): data to be encoded. In modes
2 and 3 if the postal code is empty it will be extracted from the
begining of this string (see maxicode specifications)
- public void setNumberOfCodes(int n): number of symbol in
structured appended mode. The default is 1.
- public void setPositionOfCode(int n): number of symbol in
structured appended mode. The default is 1.
- public Size getPreferredSize(): returns size needed to draw
the symbol. Can be called alter setL() or after paint().
- public void setAutoResize(bool b): if true the image will
be resized to fit the size available for the component. Thi is used
to show the symbol on the screen only.
public bool setResolution(int r): Set resolution of the printer
(in dpi). The default is 200 dpi.
- public bool setL(double l): Set length of length symbol.
The default is 25.5 millimeters.
- public void setRedraw(bool b): force recalculating the symbol
next time paint() is called
- public void setProcessTilde(bool pt): set it to true to process
the tilde escape sequence.
The following method can be used for painting the barcode on an external
graphics object:
- public void paint(Graphics g): paints the maxicode symbol.
If you need to created a image file you can do it like this:
[C#]
using J4L.RMaxicode;
...
// define variable
RMaxicode bc;
// create instance of the objact
bc = new RMaxicode();
// set barcode
properties
bc.setData("12345678");
bc.setZipCode("00000");
...
// set size and write to file
bc.Size = new System.Drawing.Size(368, 176);
bc.saveToFile("maxicode.gif","GIF");
[VBNET]
Imports J4L.RMaxicode
......
' define variable
Dim bc as RMaxicode
'create instance of the objact
bc = new RMaxicode()
' set barcode
properties
bc.setData("12345678")
bc.setZipCode("00000")
...
' set size and write to file
bc.Size = new System.Drawing.Size(368, 176)
bc.SaveToFile("maxicode.gif","GIF")
You can also use the paint() method for rendering the barcode onto
an external Graphics object:
[C#]
using J4L.RMaxicode;
using System.Drawing;
...
// create image
and graphics
Bitmap inMemoryImage =new Bitmap(300,300) ;
Graphics g= Graphics.FromImage(inMemoryImage) ;
// create barcode
RMaxicode bc=new RMaxicode();
// set barcode
properties
bc.Size.Width=300;
bc.Size.Height=300;
bc.setData("12345678");
bc.setZipCode("00000");
...
// render barcode on "g"
bc.paint(g);
[VBNET]
Imports J4L.RMaxicode
Imports System.Drawing
..............
' create image
and graphics
dim inMemoryImage as new Bitmap(300,300)
dim g as Graphics = Graphics.FromImage(inMemoryImage)
'create barcode
dim bc as RMaxicode =new RMaxicode()
' set barcode
properties
bc.Size.Width=300
bc.Size.Height=300
bc.setData("12345678")
bc.setZipCode("00000")
...
'render barcode on "g"
bc.paint(g)
RMaxicodeControl class
The class J4L.RMaxicode.RMaxicodeControl is a subclass of System.Windows.Forms.Control
and can therefore be used for placing a maxicode on a windows form.
The following method can be used to get the contained RMaxicode object:
public RMaxicode getMaxicode()
The windows forms control can be placed on a form with your IDE by
just adding our controls to the toolbox. You can also programatically
add controls to your form with the following code:
[C#]
using J4L.RMaxicode;
...
// define variable
RMaxicodeControl bc;
// create
instance of the objact
bc = new RMaxicodeControl();
// define position and size of the object on the form
bc.Location = new System.Drawing.Point(8, 8);
bc.Size = new System.Drawing.Size(368, 176);
// set barcode
properties
bc.getMaxicode().setData("12345678");
....
// add it to the form "this" is the current form.
this.Controls.Add(bc);
[VBNET]
Imports J4L.RMaxicode
.....
' define variable
dim bc as RMaxicodeControl
'create instance of the objact
bc = new RMaxicodeControl()
'define position and size of the object on the form
bc.Location = new System.Drawing.Point(8, 8)
bc.Size = new System.Drawing.Size(368, 176)
' set barcode
properties
bc.getMaxicode().setData("12345678");
...
'add it to the form "me" is the current form.
me.Controls.Add(bc)
You can print the barcode by rendering in on the Graphics objects of
the PrintDocument:
[C#]
void btnPrintClick(object
sender, System.EventArgs e)
{
// create PrintDocument and set handler
PrintDocument printDocument1=new PrintDocument();
printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
printDocument1.Print();
}
private void
printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs
e)
{
// print barcode here
bc.getMaxicode().paint(e.Graphics);
}
RMaxicodeWebControl class
The class J4L.RMaxicode.RMaxicodeControl is a subclass of WebControl
and can be used in your web applications to create maxicode barcodes.
The Web Control can be used in 2 ways:
- Include the control in a asp.net page so that it creates a barcode
and the HTML code for it. This approach will create a physical image
file on your server. In order to use this approach you must only add
the rmaxicode11.dll ( or rmaxicode10.dll if you use .NET 1.0) assembly
to your favorite IDE and drop our components on your form. The resulting
code will look like this.
<%@ Page Language="C#" %>
<%@ Register TagPrefix="n0" Namespace="J4L.RMaxicode"
Assembly="rmaxicode10" %>
<script runat="server">
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<n0:RMaxicodeWebControl id="RMaxicodeWebControl1" runat="server"
Data="12345" Country="123" LocalImageDirectory="c:\dotnet\webmatrix\test"
NumberOfCodes="1" ImageRetainTime="30" Resolution="200"
Height="131px" PositionOfCode="1" Width="333px"></n0:RMaxicodeWebControl>
<!-- Insert content here -->
</form>
</body>
</html>
The web control can be configured with the following properties:
- ImageRetainTime: (in minutes). Temporary barcode image
files will be deleted after this time.
- LocalImageDirectory: directory where the barcode images
will be created.
-ImageHTMLPrefix: directory where the barcode images will
be created, from the browser's point of view.
- ImageFile: name of the created image file.
- Use it in a aspx page to create a image on the fly. Your html page
should contain a tag like this:
<img SRC=barcode.aspx ALT=Barcode BORDER=0>
which defines a image that must be read from barcode.aspx. The
barcode.aspx page must then generate the barcode image in the
following way:
[C#]
<%@ Page
language="c#" AutoEventWireup="false" Trace="false"
Debug="false" %>
<%@Import Namespace="System.Drawing" %>
<%@Import Namespace="System.IO" %>
<%@Import Namespace="System.Drawing.Imaging" %>
<%@Import Namespace="J4L.RMaxicode" %>
<%@ OutputCache Duration="100" VaryByParam="none"
%>
<%
// define
variable
RMaxicodeWebControl bc;
// create instance of the object
bc = new RMaxicodeWebControl();
// set barcode
properties
bc.Data="12345678";
...
// create in
memory image
Bitmap inMemoryImage = new Bitmap( 200,200);
Graphics g = Graphics.FromImage(inMemoryImage);
// paint barcode
bc.getMaxicode().Size.Width=400;
bc.getMaxicode().Size.Height=400;
bc.getMaxicode().paint(g);
MemoryStream
tempStream = new MemoryStream();
// output image
to the memory stream in gif format
inMemoryImage.Save(tempStream,ImageFormat.Gif);
Response.ClearContent();
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "image/gif";
Response.BinaryWrite(tempStream.ToArray());
Response.End();
%>
[VBNET]
<%@ Page
language="VB" AutoEventWireup="false" Trace="false"
Debug="false" %>
<%@Import Namespace="System.Drawing" %>
<%@Import Namespace="System.IO" %>
<%@Import Namespace="System.Drawing.Imaging" %>
<%@Import Namespace="J4L.RMaxicode" %>
<%@ OutputCache Duration="100" VaryByParam="none"
%>
<%
' define variable
dim bc as RMaxicodeWeb = new RMaxicodeWeb()
' set barcode
properties
bc.Data="12345678"
...
' create in
memory image
dim inMemoryImage as Bitmap= new Bitmap( 200,200)
dim g as Graphics = Graphics.FromImage(inMemoryImage)
' paint barcode
bc.getMaxicode().Size.Width=400
bc.getMaxicode().Size.Height=400
bc.getMaxicode().paint(g)
dim tempStream
as MemoryStream = new MemoryStream()
' output image
to the memory stream in gif format
inMemoryImage.Save(tempStream,ImageFormat.Gif)
Response.ClearContent()
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "image/gif"
Response.BinaryWrite(tempStream.ToArray())
Response.End()
%>
Important Note:
In order to property print a maxicode embeded in a HTML page you must
use the <IMG> tag. Note that you will need to use the attibutes
height and width
in order to achieve the correct size of the maxicode on the printed
page.
This is a simple HTML page that contains a maxicode barcode:
<HTML>
<HEAD>
<TITLE>Servlet Example META http-equiv=Content-Type
content="text/html; charset=windows-1252">
</HEAD>
<BODY bgColor=#ffffff>
This is your Maxicode:
<IMG height=100 width=100
src="barcode.aspx" >
</BODY>
</HTML>
References
You can find more information about maxicode at:
|