Here i have given the Frontend and Backend for Generating Code128 Barcode.When i click the button i get strange sequence of characters,digits and symbols.Please help me to rectify the error.I have used iTextsharp.dll of iTextsharp to generate this Barcode.
Please see the attached txt file that contains the code!
----Frontend----
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="code128_genr.aspx.cs" Inherits="BCRS.code128_genr" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" /></div>
</form>
</body>
</html>
----CodePart----
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.Drawing;
using System.Drawing.Text;
using System.Drawing.Imaging;
using System.IO;
namespace BCRS
{
public partial class code128_genr : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string strBarCode = string.Empty;
String font;
font = "Code 128";
strBarCode = TextBox1.Text.ToString();
Barcode128 code128 = new Barcode128();
code128.CodeType = Barcode.CODE128;
code128.ChecksumText = true;
code128.GenerateChecksum = true;
code128.StartStopText = true;
code128.Code = TextBox1.Text.ToString();
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(code128.CreateDrawingImage(System.Drawing.Color.Black, System.Drawing.Color.White));
Graphics g = Graphics.FromImage(bm);
g.DrawRectangle(Pens.White, 1, 1, 45 - 3, 176 - 3);
g.DrawRectangle(Pens.Gray, 2, 2, 45 - 3, 176 - 3);
g.DrawRectangle(Pens.Black, 0, 0, 45, 176);
bm.Save(Response.OutputStream, ImageFormat.Jpeg);
g.Dispose();
bm.Dispose();
Response.End();
}
}
}
--output--Take An Instance when it is run and we enter text in the textbox say for example "wikipedia" and When The Button Is Clicked the output is ----
ÿØÿàJFIF``ÿÛC $.' ",#(7),01444'9=82<.342ÿÛC 2!!22222222222222222222222222222222222222222222222222ÿÀ†"ÿÄ ÿĵ