RBarcode 1D & 2D for .NET

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

 

Introduction

RBarcode for .Net is a control that will allow you to create 1 dimensional and 2 dimensional barcodes for your .NET applications. It can be used as a windows form control or as a web server control.

1D Barcodes types

The following is a short description of some of the suported barcode types:

 

Introduction to PDF 417

 

PDF stands for “Portable Data File.” A two-dimensional symbology (2D), a single PDF417 symbol carries up to 1.1 kilobytes of machine-readable data in a space no larger than a standard bar code. And, unlike one-dimensional bar codes (1D), which are just a key linked to a database, PDF417 symbols contain the database itself. That means, you don't have to store an article number in the barcode but you can also store the name , the size , the color, the name of the manufacturer etc...

 

Introduction to Datamatrix

Data Matrix is a two-dimensional (2D) matrix symbology which is made up of square modules arranged within a perimeter finder pattern. It can encode up to 3116 characters from the entire 256 byte ASCII character set. The symbol consists of data regions which contain square modules set out in a regular array. Large ECC 200 symbols contain several regions. Each data region is delimited by a finder pattern, and this is surrounded on all four sides by a quiet zone border (margin).

 

 

ECC 200 symbols have an even number of rows and an even number of columns. Most of the symbols are square with sizes from 10 x 10 to 144 x 144. Some symbols however are rectangular with sizes from 8 x 18 to 16 x 48. All ECC 200 symbols can be recognized by the upper right corner module being light (binary 0).

ECC200 is the newest version of data matrix and supports advanced encoding error checking and correction algorithms (reed-solomon). This algorithms allow the recognition of barcodes that are up to 60% damaged.

The barcode supports two optional mechanisms:

RDataMatrix supports:

Formats

RDataMatrix supports all data matrix formats. The following table contains the size , the capacity and the correction error features of each format:

Size

Numeric Capacity

Alphanumeric capacity

Binary capacity

Max Correctable

Error/Erasure

10 x 10

6

3

1

2

12 x 12 10 6 3 3
14 x 14 16 10 6 5/7
16 x 16 24 16 10 6/9

18 x 18

36

25

16

7/11

20 x 20 44 31 20 9/15

22 x 22

60

43

28

10/17

24 x 24

72

52

34

12/21

26 x 26

88

64

42

14/25

32 x 32 124 91 60 18/33
36 x 36 172 127 84 21/39
40 x 40 228 169 112 24/45
44 x 44 288 214 142 28/53
48 x 48 348 259 172 34/65
52 x 52 408 304 202 42/78
64 x 64 560 418 278 56/106
72 x 72 736 550 366 72/132
80 x 80 912 682 454 96/180
88 x 88 1152 862 574 112/212
96 x 96 1392 1042 694 136/260
104 x 104 1632 1222 814 168/318
120 x 120 2100 1573 1048 204/390
132 x 132 2608 1954 1302 248/472
144 x 144 3116 2335 1556 310/590
8 x 18 10 6 3 3
8 x 32 20 13 8 5
12 x 26 32 22 14 7/11
12 x 36 44 31 20 9/15
16 x 36 64 46 30 12/21
16 x 48 98 72 47 14/25

Encoding

The data represented in the symbol can be compressed using one or several of the following algorithms:

All encoding system can be used to encode any data, but for example, encoding binary data with C40 generates much more overhead (longer symbol) than with BASE256.

Control characters

RDataMatrix uses the tilde character ~ to recognize some special characters in the input data. The following possibilities are available:


 

Installation

 

After unzipping the file you have received or downloaded, you must add one of the following files to your IDE ( for example, Visual Studio.Net or #develop):

The files are located in the net1_1 and the net1_0 subdirectories.

Whenever you use one of our controls don't forget to import the namespace:

[C#]

using J4L.RBarcode;

...

 

[VBNET]

Imports J4L.RBarcode

.....

 

Example

The product contains a sample application (and its c# source code) which demonstrates the use of the windows forms control. The source code of the sample application is located in the FormExample subdirectory .

The compiled version is located under the net1_0 (compiled with .NET 1.0.3705 ) and the net1_1 (compiled with .NET 1.1.4322 ) subdirectories .

The Example application will allow you to create any type of barcodes, save them to a gif file of print them. In the main window you must select the type of barcode you want to create.

In the next windows you can then enter the barcode specific information and create the barcode.

 

 

Use of the windows forms Controls

(Note: all examples use the Rbarcode1D class, however you can use RDatamatrix and RPDF417 classes in the same way)

The windows forms control can be placed on a form with your IDE by just adding our controls to the toolbox. You can also programmatically add controls to your form with the following code:

[C#]

using J4L.RBarcode;

...

// define variable
Rbarcode1D bc;
// create instance of the objact
bc = new Rbarcode1D();
// 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";
bc.BarType=Rbarcode1D.tbarType.CODE128;

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

[VBNET]

Imports J4L.RBarcode

.....

' define variable
dim bc as Rbarcode1D
'create instance of the objact
bc = new Rbarcode1D()
'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"
bc.BarType=Rbarcode1D.tbarType.CODE128

'add it to the form "me" is the current form.
me.Controls.Add(bc)

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

[C#]

using J4L.RBarcode;

...

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

// set barcode properties
bc.Code="12345678";
bc.BarType=Rbarcode1D.tbarType.CODE128;

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

[VBNET]

Imports J4L.RBarcode

......

' define variable
Dim bc as Rbarcode1D
'create instance of the objact
bc = new Rbarcode1D()

' set barcode properties
bc.Code="12345678"
bc.BarType=Rbarcode1D.tbarType.CODE128

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

 

You can also use the paintBarcode 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
Rbarcode1D bc=new Rbarcode1D();

// set barcode properties
bc.Code="12345678";
bc.BarType=Rbarcode1D.tbarType.CODE128;

// render barcode on "g"
bc.paintBarcode(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 Rbarcode1D =new Rbarcode1D()

' set barcode properties
bc.Code="12345678"
bc.BarType=Rbarcode1D.tbarType.CODE128

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

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.paintBarCode(e.Graphics);
}

 

Use of the web control with ASP

(Note: all examples use the Rbarcode1DWeb class, however you can use RDatamatrixWeb and RPDF417Web classes in the same way)

The Web Controls 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 rbarcodeweb.dll ( or rbarcodeweb10.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="VB" %>
    <%@ Register TagPrefix="n0" Namespace="J4L.RBarcode" Assembly="rbarcodeweb" %>
    <html>
    <head>
    </head>
    <body>
    <form runat="server">
    <n0:Rbarcode1DWeb id="Rbarcode1DWeb1" runat="server" Code="12345678" BarType="CODE128"></n0:Rbarcode1DWeb>
    <!-- Insert content here -->
    </form>
    </body>
    </html>

  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
    Rbarcode1DWeb bc;
    // create instance of the object
    bc = new Rbarcode1DWeb();

    // set barcode properties
    bc.Code="12345678";
    bc.BarType=Rbarcode1DWeb.tbarType.CODE128;

    // create in memory image
    Bitmap inMemoryImage = new Bitmap( 200,200);
    Graphics g = Graphics.FromImage(inMemoryImage);
    // paint barcode
    bc.paintBarcode(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 Rbarcode1DWeb = new Rbarcode1DWeb()

    ' set barcode properties
    bc.Code="12345678"
    bc.BarType=Rbarcode1DWeb.tbarType.CODE128

    ' create in memory image
    dim inMemoryImage as Bitmap= new Bitmap( 200,200)
    dim g as Graphics = Graphics.FromImage(inMemoryImage)
    ' paint barcode
    bc.paintBarcode(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()
    %>

 

Classes and Members

Rbarcode1D (windows control) and Rbarcode1DWeb (server control)

Methods

Properties

How to use the checkCharacter property:

If you are suppling the code with the check digit already calculated, you must set BarCheckCharacter to false. If you want the software to calculate the checksum for you, you must set barcheckCharacter to true (default).

For EAN and UPC have fixed length and therefore you only have the following possibilities:


 

RPDF417 (windows control) and RPDF417Web (server control)

Methods

Properties


 
 

RDatamatrix (windows control) and RDatamatrixWeb (server control)

Methods

Properties