Thanks to iTextSharp developer Team
——————————– My Code —————————-
private System.Drawing.Image CreateBarcode(string data)
//Bitmap barCode = new Bitmap(1, 1);
Barcode128 code128 = new Barcode128(); // barcode type
code128.Code = data;
System.Drawing.Image barCode = code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White);
//barCode.Save(Server.MapPath(“~/barcode.gif”), System.Drawing.Imaging.ImageFormat.Gif); //save file
public static byte ImageToByte(System.Drawing.Image img)
ImageConverter converter = new ImageConverter();
return (byte)converter.ConvertTo(img, typeof(byte));
// adding new column to datatable and assign value
System.Data.DataColumn newColumn = new System.Data.DataColumn(“barCode”, typeof(System.Byte));
newColumn.DefaultValue = ImageToByte(CreateBarcode(APPLICATION_SN));
I have looked for several options and libraries to generate a code128 barcode. It appears that there are three versions of code128
128C is for digits only, 128A is for case insensitive barcodes and 128B is case sensitive. If you want to know more details, I recommend the Wikipedia page of code128.
Somehow other libraries I found did not clearly show the differences between the code128 subtypes. After some Google queries, I found out that the free open source library which I used for generating PDF’s also has capabilities for generating barcodes.
iText# (iTextSharp) is a port of the iText open source java library for PDF generation written entirely in C# for the .NET platform.
[more]So before I show you my code snippets for a generic Code128 barcode, here is the download link for the binary iText# DLL.
I have chosen GIF over JPG for displaying barcodes online. It appears to be sharper.
So here is my implementation of the auto generated ProcessRequest method of the HTTP handler:
Please do not forget to add iTextSharp and iTextSharp.text.pdf to your usings!
Good luck with your Code128 Barcodes!