Barcode Generator in asp.net using C#


Bar code Generate in asp.net using C#:

Requirements:

Technology  :  asp.net ,C#
FontsIDAutomationHC39M


Design:




Source Code:
Default.aspx

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

<table>
<tr>
<td>
<asp:Label ID="lid" Text="ID" runat="server"></asp:Label>
</td>
<td>
 <asp:TextBox ID="txtCode" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lname" Text="NAME" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtname" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lquantity" Text="QUANTITY" runat="server"></asp:Label>
</td>
<td>
 <asp:TextBox ID="txtquantity" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lamount" Text="AMOUNT" runat="server"></asp:Label>
</td>
<td>
<asp:TextBox ID="txtamount" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
 <asp:Label ID="ldate" Text="DATE" runat="server"></asp:Label>
</td>
<td>
 <asp:TextBox ID="txtdate" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td align="center" colspan="2">
<asp:Button ID="btnGenerate" Text="Generate" runat="server" 
        onclick="btnGenerate_Click"/>
</td>
</tr>
<tr>
<td>
<asp:PlaceHolder ID="plBarCode" runat="server">
    <asp:Image ID="Image1" runat="server" />

</asp:PlaceHolder>
</td>
</tr>
</table>
           
</asp:Content>



Code Behind page:
default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Guid invoiceNumber = Guid.NewGuid();
        Response.Write(invoiceNumber);
    }
    protected void btnGenerate_Click(object sender, EventArgs e)
    {
       
        string barCode =txtCode.Text+txtname.Text+txtquantity.Text+txtamount.Text+txtdate.Text;
        System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
        using (Bitmap bitMap = new Bitmap(barCode.Length * 21, 80))
        {
            using (Graphics graphics = Graphics.FromImage(bitMap))
            {
                Font oFont = new Font("IDAutomationHC39M", 15);
                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);
            }
            plBarCode.Controls.Add(imgBarCode);
        }
    }
}

Download This Font:

IDAutomationHC39M


Download this font paste in control panel------>font folder


Output



Download Source Code :Barcode Source Code