RAztec Code for .NET

Copyright J4L (http://www.java4less.com) 2003.

Introduction

The package RAztec contains the classes you need to create Aztec barcodes within your .NET applications.

Aztec Code is a 2D matrix symbology made up of square modules on a square grid, with a square bullseye pattern at their center. Aztec Code symbols can encode large amounts of data with user defined error correction level.

The smallest format can encode 13 numeric , 12 alphabetic characters or 6 bytes of data, while the largest format can encode 3832 numeric ,3067 alphabetic characters or 1914 bytes of data.

available formats are:

 

Rows / columns (number of modules/squares)
Capacity (digits)
Capacity (text)
Capacity (binary data)
CONFIGURATION_15X15_COMPACT
13
12
6
CONFIGURATION_19X19
18
15
8
CONFIGURATION_19X19_COMPACT
40
33
19
CONFIGURATION_23X23
49
40
24
CONFIGURATION_23X23_COMPACT
70
57
33
CONFIGURATION_27X27
84
68
40
CONFIGURATION_27X27_COMPACT
110
89
53
CONFIGURATION_31X31
128
104
62
CONFIGURATION_37X37
178
144
87
CONFIGURATION_41X41
232
187
114
CONFIGURATION_45X45
294
236
145
CONFIGURATION_49X49
362
291
179
CONFIGURATION_53X53
433
348
214
CONFIGURATION_57X57
516
414
256
CONFIGURATION_61X61
601
482
298
CONFIGURATION_67X67
691
554
343
CONFIGURATION_71X71
793
636
394
CONFIGURATION_75X75
896
896
446
CONFIGURATION_79X79
1008
808
502
CONFIGURATION_83X83
1123
900
559
CONFIGURATION_87X87
1246
998
621
CONFIGURATION_91X91
1378
1104
687
CONFIGURATION_95X95
1511
1210
753
CONFIGURATION_101X101
1653
1324
824
CONFIGURATION_105X105
1801
1442
898
CONFIGURATION_109X109
1956
1566
976
CONFIGURATION_113X113
2216
1694
1056
CONFIGURATION_117X117
2281
1826
1138
CONFIGURATION_121X121
2452
1963
1224
CONFIGURATION_125X125
2632
2107
1314
CONFIGURATION_131X131
2818
2256
1407
CONFIGURATION_135X135
3007
2407
1501
CONFIGURATION_139X139
3205
2565
1600
CONFIGURATION_143X143
3409
2728
1702
CONFIGURATION_147X147
3616
2894
1806
CONFIGURATION_151X151
3832
3067
1914

 

Compact formats can be used to encode short messages in a more efficient manner than full range formats. Note that reader/decoder can autodiscrimanate between both formats.

There are also a set of 256 special formats called "Aztec runes" which can be used for encoding values 0 to 255 for special applications.

 

RAztecCode supports:

 

 

Sample Application

In order to run the sample application you must execute RAztecDemo11.exe or RAztecDemo10.exe.

 

 

In the sample application you can set all properties of the Aztec code symbology.

You can execute the following commands:

 

RAztec class

The main class for creating aztec barcodes is J4L.RBarcode.RAztec. It is a subclass of System.Windows.Forms.Control and can therefore be used for placing a barcode on a windows form.

The following properties allows you to configurate the barcode:

Structured Append properties

 

The following method can be used for painting the barcode on an external graphics object:

If you need to created a image file you can do it like this:

[C#]

using J4L.Rbarcode;

...

// define variable
RAztec bc;
// create instance of the objact
bc = new RAztec();

// set barcode properties
bc.Code="12345678";

...



// set size and write to file
bc.Size = new System.Drawing.Size(368, 176);
bc.saveToFile("aztec.gif","GIF");

[VBNET]

Imports J4L.RBarcode

......

' define variable
Dim bc as RAztec
'create instance of the object
bc = new RAztec()

' set barcode properties
bc.Code="12345678"
...

' set size and write to file
bc.Size = new System.Drawing.Size(368, 176)
bc.SaveToFile("aztec.gif","GIF")

 

You can also use the paint() method for rendering the barcode onto an external Graphics object:

[C#]

using J4L.RBarcode;
using System.Drawing;

...

// create image and graphics
Bitmap inMemoryImage =new Bitmap(300,300) ;
Graphics g= Graphics.FromImage(inMemoryImage) ;

// create barcode
RAztec bc=new RAztec();

// set barcode properties
bc.Size=new Size(300,300);
bcCode="12345678";
...


// render barcode on "g"
bc.paint(g);

[VBNET]

Imports J4L.RBarcode
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 RAztec =new RAztec()

' set barcode properties
bc.Size=new Size(300,300);
bc.Code="12345678"
...


'render barcode on "g"
bc.paint(g)

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.RBarcode;

...

// define variable
RAztec bc;
// create instance of the objact
bc = new RAztec();
// 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.Code="12345678";
....

// add it to the form "this" is the current form.
this.Controls.Add(bc);

[VBNET]

Imports J4L.RBarcode

.....

' define variable
dim bc as RAztec
'create instance of the objact
bc = new RAztec()
'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.Code="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.paint(e.Graphics);
}

RAztecWeb class

The class J4L.RBarcode.RAztecWeb is a subclass of WebControl and can be used in your web applications to create barcodes.

The Web Control can be used in 2 ways:

  1. 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 raztec11.dll ( or raztec10.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.RBarcode" Assembly="raztec10" %>
    <script runat="server">

    </script>
    <html>
    <head>
    </head>
    <body>
    <form runat="server">
    <n0:RAztecWeb id="RAztecWeb1" runat="server" Data="12345" Country="123" LocalImageDirectory="c:\dotnet\webmatrix\test" NumberOfCodes="1" ImageRetainTime="30" Resolution="200" Height="131px" PositionOfCode="1" Width="333px"></n0:RAztecWeb>
    <!-- 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.




  2. 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.RBarcode" %>
    <%@ OutputCache Duration="100" VaryByParam="none" %>
    <%
    // define variable
    RAztecWeb bc;
    // create instance of the object
    bc = new RAztecWeb();

    // set barcode properties
    bc.Code="12345678";
    ...

    // create in memory image
    Bitmap inMemoryImage = new Bitmap( 200,200);
    Graphics g = Graphics.FromImage(inMemoryImage);
    // paint barcode
    bc.getAztec().Size=new Size(300,300);
    bc.getAztec().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.RBarcode" %>
    <%@ OutputCache Duration="100" VaryByParam="none" %>
    <%

    ' define variable
    dim bc as RAztecWeb = new RAztecWeb()

    ' set barcode properties
    bc.Code="12345678"
    ...

    ' create in memory image
    dim inMemoryImage as Bitmap= new Bitmap( 200,200)
    dim g as Graphics = Graphics.FromImage(inMemoryImage)
    ' paint barcode
    bc.getAztec().Size=new Size(300,300);
    bc.getAztec().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 properly print a aztec code 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 aztec code on the printed page.

This is a simple HTML page that contains a aztec barcode:

<HTML>
<HEAD>

<TITLE>Servlet Example META http-equiv=Content-Type content="text/html; charset=windows-1252">

</HEAD>
<BODY bgColor=#ffffff>

This is your Aztec Code:
<IMG height=100 width=100 src="aztec.aspx" >

</BODY>
</HTML>