Barcode
Font
First we should download the Font from the Url which is given
below
Once downloaded follow the below steps.
1. Extract the ZIP file.
2. Click and Execute INSTALL.exe file.
*.aspx
<div>
<table
class="auto-style1">
<tr>
<td>
<asp:Label ID="lblNumber"
runat="server" style="text-align:right" Text="Enter
Number"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtNumber"
runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:Button ID="btnGenerate"
runat="server" Text="Generate"
OnClick="btnGenerate_Click" style="height: 26px" />
</td>
</tr>
<tr>
<td>
<asp:PlaceHolder ID="PlaceHolder1"
runat="server"></asp:PlaceHolder>
</td>
</tr>
</table>
</div>
*.CS
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication3
{
public partial class WebForm1 :
System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
protected void
btnGenerate_Click(object sender, EventArgs e)
{
string barCode =
txtNumber.Text;
System.Web.UI.WebControls.Image imgBarCode = new
System.Web.UI.WebControls.Image();
using (Bitmap
bitMap = new Bitmap(barCode.Length * 40, 80))
{
using (Graphics graphics = Graphics.FromImage(bitMap))
{
Font oFont = new Font("IDAutomationHC39M", 16);
PointF point = new PointF(2f, 2f);
SolidBrush blackBrush = new SolidBrush(Color.Black);
SolidBrush whiteBrush = new SolidBrush(Color.White);
graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width,
bitMap.Height);
graphics.DrawString("*" + barCode + "*",
oFont, blackBrush, point);
}
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
Convert.ToBase64String(byteImage);
imgBarCode.ImageUrl = "data:image/png;base64," +
Convert.ToBase64String(byteImage);
}
PlaceHolder1.Controls.Add(imgBarCode);
}
}
}
}