How to Generate UPC-A in Crystal Reports
UPC-A is one of the GS1 barcodes which have been used world widely in Logistics. The barcode symbology UPC-A is fixed-length and encodes twelve digits including one mandatory checksum digit.
Barcode Generator for Crystal Report is a robust .NET SDK developed for Crystal Report development, which generates 20+ linear & 2D barcode in reports. The generator itself is a .NET control library that encapsulates barcode generation features. The control could be installed and used easily in Crystal Reports for .NET.
UPC-A Crystal Report Generator integrates with Crystal Report, and generates UPC-A barcodes in the report. With it, you are able to generate high quality UPC-A barcode images without the use of any barcode fonts. This document tells how to generate & print UPC-A barcodes in Crystal Reports.
UPC-A Generator for Crystal Report Features
Valid Data |
Valid character set includes:
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 |
Checksum Calculation |
Automatically calculate the mandatory checksum digit basing on your specified data string. |
Supplement Barcode |
Print possible two and five digits supplement barcode symbol for supplement information encoding. |
Size Adjustments |
Include flexible size customization solutions, including the size setting of bar, space, margins, and text. |
Human-Readable Text |
Display adjustable human-readable text below the UPC-A barcode symbol. |
Royalty-free Distribution |
Offer royalty-free license with purchase license. |
UPC-A Generator for Crystal Report Requirements
Windows OS
- Windows 7 - Windows Vista - Windows XP |
Development Environments
- .NET 2.0, 3.0 or later version - C#, VB.NET, Managed C++, Borland Delphi for .NET - Microsoft Visual Studio 2005/2008/2010 |
How to Create a Crystal Report for .NET
- Download Barcode Generator for Crystal Report and unzip;
- Open Visual Studio and create a web project using "ASP.NET Crystal Report Web Site";
- Select the Crystal Report Template, then name and locate the report;
- When the Crystal Report Gallery dialog box appears, accept the defaults of "Use Report Expert" and "Standard Report", and click "OK";
Setup the Crystal Report in .NET
- Select "ADO.NET" in "Create New Connection" when Crystal Reports wizard dialogue pops up;
- Browse and find "CustomerDataSet.xsd" in your downloaded sample dataset package (or any other dataset of your own), then click "Finish";
- Click on the Tables node to expand;
- Drag and drop the table name to the window titled Tables In Report, and click "Next";
- To display fields on the report, select them at the Field tab, and click "Finish";
How to Generate UPC-A in Crystal Report for .NET
- Drag and drop the field named âBarcodeâ to the report in Crystal Report1.rpt;
- Open Form1.cs in Design view, and add Barcode .linearbarcode.aspnet.dll to the project reference;
- Double click Form1 to enter Form1.cs, and copy the sample code into the method Form_Load;
- Using the namespace âBizcode.linearbarcodeâ if your report is created in C#.NET;
- Run the web project;
UPC-A Generation Sample Code
Run the web project with the sample codings below;
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection aConnection = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Demo/BarcodeDemoData.
mdb");
aConnection.Open();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter
("select * from Customer", aConnection);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
//add a new column named "Barcode" to the DataSet, the new column data
type is byte[]
ds.Tables[0].Columns.Add(new DataColumn("Barcode", typeof(byte[])));
WebLinearBarcode barcode = new WebLinearBarcode ();
barcode. Symbology = Symbology.UPCA;
foreach (DataRow dr in ds.Tables[0].Rows)
{
barcode.Data = (int)dr["CustomerId"] + "";
byte[] imageData = barcode.drawBarcodeAsBytes();
dr["Barcode"] = imageData;
}
CrystalReportSource1.ReportDocument.Load(Server.MapPath
("CrystalReport1.rpt"));
CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables[0]);
CrystalReportSource1.DataBind();
aConnection.Close();
}
Protected Sub CrystalReportViewer1_Init(ByVal sender As Object,
ByVal e As System.EventArgs) Handles CrystalReportViewer1.Init
Dim aConnection As New OleDbConnection
("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:/Demo/BarcodeDemoData.mdb")
aConnection.Open()
Dim dataAdapter As New OleDbDataAdapter("select * from Customer",
aConnection)
Dim ds As New DataSet()
dataAdapter.Fill(ds)
'add a new column named "Barcode" to the DataSet, the new column
data type is byte[]
ds.Tables(0).Columns.Add(New DataColumn("Barcode", GetType(Byte())))
Dim barcode As New WebLinearBarcode ()
barcode. Symbology = Symbology.UPCA
For Each dr As DataRow In ds.Tables(0).Rows
barcode.Data = CInt(dr("CustomerId")) & ""
Dim imageData As Byte() = barcode.drawBarcodeAsBytes()
dr("Barcode") = imageData
Next
CrystalReportSource1.ReportDocument.Load(Server.MapPath
("CrystalReport1.rpt"))
CrystalReportSource1.ReportDocument.SetDataSource(ds.Tables(0))
CrystalReportSource1.DataBind()
aConnection.Close()
End Sub