BarCodes Not Generating! [Resolved]

Posted by Coolbharat under ASP.NET on 11/29/2013 | Points: 10 | Views : 4390 | Status : [Member] | Replies : 6
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ÿÀ†"ÿÄ ÿĵ




Responses

Posted by: vishalneeraj-24503 on: 11/29/2013 [Member] [MVP] Platinum | Points: 50

Up
0
Down

Resolved
Please use below links:-
http://stackoverflow.com/questions/4917809/barcode-with-text-under-using-itextsharp
http://www.codeproject.com/Tips/616116/Generating-Barcode-for-a-Sale-Purchase-System-Usin
http://www.jphellemons.nl/post/Make-a-code128-barcode-with-C-sharp-and-iTextSharp.aspx
http://rsmmukesh.blogspot.in/2013/04/generate-barcode-in-c-aspnet.html

Coolbharat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mariah on: 12/1/2013 [Member] Starter | Points: 50

Up
0
Down

Resolved
you can check this barcode 128 code C#
http://www.keepautomation.com/csharp_barcode/code_128.html
BarCode code128 = new BarCode();
code128.Symbology = KeepAutomation.Barcode.Symbology.Code128Auto;
code128.CodeToEncode = "Code128Csharp";

//Apply checksum for Code 128 barcode.
code128.ChecksumEnabled = true;

// Print Code 128 in specified image format like Png, Jpeg, Gif, Tiff, Bmp, etc.
code128.ImageFormat = ImageFormat.Png;

// Display checksum in the Code 128 human-readable text
code128.DisplayChecksum = true;

// Set Code 128 image size

// Code 128 unit of measure, Pixel, Cm and Inch supported.
code128.BarcodeUnit = BarcodeUnit.Pixel;
// Code 128 image resolution in DPI.
code128.DPI = 72;
// Code 128 bar module width (X dimention)
code128.X = 3;
// Code 128 bar module height (Y dimention)
code128.Y = 60;
// Image left margin size, a 10X is automatically added according to
code128.LeftMargin = 0;
// Image left margin size, a 10X is automatically added according to
code128.RightMargin = 0;
// Code 128 image top margin size
code128.TopMargin = 0;
// Code 128 image bottom margin size
code128.BottomMargin = 0;
// Code 128 image orientation, 0, 90, 180, 270 degrees supported.
code128.Orientation = KeepAutomation.Barcode.Orientation.Degree0;

// Set Code 128 human readable text

// Display human readable text
code128.DisplayText = true;
code128.TextFont = new Font("Arial", 10f, FontStyle.Regular);
// Space between barcode and text beneath.
code128.TextMargin = 6;

// Generate Code 128 barcodes in image format PNG
code128.generateBarcodeToImageFile("C://barcode-code128-csharp.png");

/* Create Code 128 barcodes in Stream object
code128.generateBarcodeToStream(".NET System.IO.Stream Object");

Draw & Print Code 128 barcodes to Graphics object
code128.generateBarcodeToGraphics(".NET System.Drawing.Graphics Object");

Generate Code 128 barcodes & write to byte[]
byte[] barcodeInBytes = code128.generateBarcodeToByteArray();

Generate Code 128 barcodes & encode to System.Drawing.Bitmap object
Bitmap barcodeInBitmap = code128.generateBarcodeToBitmap();
*/

Coolbharat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 11/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Also refer-
http://go4answers.webhost4life.com/Example/itextsharp-barcode-image-pdf-fly-94483.aspx
http://www.vbforums.com/showthread.php?620242-Counting-Particular-Letter-Occurrences-in-a-String
http://forums.asp.net/t/1599409.aspx

Coolbharat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Coolbharat on: 11/30/2013 [Member] Starter | Points: 25

Up
0
Down
Gone through the websites urls you have reffered.Not of much help!Can you pin point what's the error in my code or any extra modifications i need for this to work as a web application with iTextsharp....

Coolbharat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Coolbharat on: 12/16/2013 [Member] Starter | Points: 25

Up
0
Down
The jphellemons blog when studied deeply cleared the confusion i had and ultimately the problem was solved.Also the KeepAutomation link given is wonderful.

Coolbharat, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Coolbharat on: 12/16/2013 [Member] Starter | Points: 25

Up
0
Down
Thanks everybody for taking out their precious time to help me out.A lot of thanks again!!!!

Coolbharat, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response