Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET1.0 .NET1.1 .NET2.0 .NET3.0 C# , +
I want to use IDAutomationHC39M in C# and asp.net using TextBox and Button click . when i enter ID number and click button it should print in Zebra Printing Machine with Barcode...
Posted 8-Sep-12 0:41am
Comments
OriginalGriff at 8-Sep-12 5:46am
   
And?
 
You forgot to ask a question...
Use the "Improve question" widget to edit your question and provide better information.
ooffooooo at 8-Sep-12 6:52am
   
I Have A process to print ID with Barcode i want to use IDAutomationHC39M i just want to use this with textbox when i enter the ID and click button it should print ID with Barcode in thermal printer .
OriginalGriff at 8-Sep-12 7:03am
   
That's still not a question - what are you having problems with?
What have you tried so far?
Where are you stuck?
ooffooooo at 9-Sep-12 4:14am
   
what should i put in the place of path and imgPath
 
public void CreateBarcode(string data) {
imgPath = string.Format("{0}{1}.png", path, data);
Bitmap barcode = new Bitmap(1, 1);
Font threeOfNine = new Font("IDAutomationHC39M", 60,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point);
Graphics graphics = Graphics.FromImage(barcode);
SizeF dataSize = graphics.MeasureString(data, threeOfNine);
barcode = new Bitmap(barcode, dataSize.ToSize());
graphics = Graphics.FromImage(barcode);
graphics.Clear(Color.White);
graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
graphics.DrawString(data, threeOfNine, new SolidBrush(Color.Black), 0, 0);
graphics.Flush();
threeOfNine.Dispose();
graphics.Dispose();
barcode.Save(imgPath);
}
Sandeep Mewara at 8-Sep-12 9:50am
   
Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it's not that hard.
2. Formulate what was done by you that looks like an issue/not working.
ooffooooo at 9-Sep-12 4:16am
   
i tried this what should put in the place of Path and imgPath...
ooffooooo at 9-Sep-12 4:16am
   
public void CreateBarcode(string data) {
imgPath = string.Format("{0}{1}.png", path, data);
Bitmap barcode = new Bitmap(1, 1);
Font threeOfNine = new Font("IDAutomationHC39M", 60,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point);
Graphics graphics = Graphics.FromImage(barcode);
SizeF dataSize = graphics.MeasureString(data, threeOfNine);
barcode = new Bitmap(barcode, dataSize.ToSize());
graphics = Graphics.FromImage(barcode);
graphics.Clear(Color.White);
graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
graphics.DrawString(data, threeOfNine, new SolidBrush(Color.Black), 0, 0);
graphics.Flush();
threeOfNine.Dispose();
graphics.Dispose();
barcode.Save(imgPath);
}

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

"what should i put in the place of path and imgPath"
public void CreateBarcode(string data) {
    imgPath = string.Format("{0}{1}.png", path, data);
    Bitmap barcode = new Bitmap(1, 1);
    Font threeOfNine = new Font("IDAutomationHC39M", 60,
        System.Drawing.FontStyle.Regular,
        System.Drawing.GraphicsUnit.Point);
    Graphics graphics = Graphics.FromImage(barcode);
    SizeF dataSize = graphics.MeasureString(data, threeOfNine);
    barcode = new Bitmap(barcode, dataSize.ToSize());
    graphics = Graphics.FromImage(barcode);
    graphics.Clear(Color.White);
    graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixel;
    graphics.DrawString(data, threeOfNine, new SolidBrush(Color.Black), 0, 0);
    graphics.Flush();
    threeOfNine.Dispose();
    graphics.Dispose();
    barcode.Save(imgPath);
}
 

I assume that you got this code from a website, and haven't bothered too much to look at what it does.
 
That code fragment creates a barcode in an Image class instance, and saves it to a file - from your description you don't want to do that, you just want to print the barcode.
So, there are two ways to do this:
1) Remove all references to path, and instead of Saving the bitmap, return it to your application as an Image and print that directly onto your print context, or PrintDocument.
2) Use some of that code to print the barcode directly onto your print context or PrintDocument.
 
The latter will give you better results, as the barcode will be printed at a suitable resolution for teh actual print job, instead of being printed initially to a "random" bitmap resolution, then redrawn to the actual print resolution, which will introduce both artefacts and errors which will degrade the readability of the final barcode.
  Permalink  
Comments
ooffooooo at 9-Sep-12 6:56am
   
Yes i got this from web
if i get that barcode in TextBox It will be helpfull to me .. can u edit that code for me plsssssss
 
i am using this code for getting print its working fine
protected void Button2_Click(object sender, EventArgs e)
{

Print(TextBox2.Text.ToString());
 
}
private void Print(string recordIdCount)
{
StringBuilder sb = new StringBuilder();
sb.Append("<script type = 'text/javascript'>");
sb.Append("window.onload = new function(){");
sb.Append("var printWin = window.open('', '', 'left=0");
sb.Append(",top=0,width=1000,height=600,status=0');");
sb.Append("printWin.document.write(\"");
sb.Append(recordIdCount);
sb.Append("\");");
sb.Append("printWin.document.close();");
sb.Append("printWin.focus();");
sb.Append("printWin.print();");
sb.Append("printWin.close();};");
sb.Append("</script>");
ClientScript.RegisterStartupScript(this.GetType(), "key", sb.ToString(), false);
}
OriginalGriff at 9-Sep-12 7:13am
   
You can't put a barcode in a textbox - a barcode is a graphical item, not a text item.
It doesn't work like that.
You will have to send the barcode as a Picture instead, and be aware that it may not be readable if you are putting it onto a webpage, with the intention of printing it - barcodes are very sensitive to light-and-dark bar widths, and it doesn't take much to make them unreadable. Making it reasonably large can help!
ooffooooo at 9-Sep-12 7:35am
   
ok then if i put just ID in Textbox and want to get print along with barcode how can i do that??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 186
4 Aajmot Sk 153
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 9 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100