Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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
Comments
OriginalGriff 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.
Mohammed Abdul Muqeet 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 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?
Mohammed Abdul Muqeet 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 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.

1 solution

"what should i put in the place of path and imgPath"
C#
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.
 
Share this answer
 
Comments
Mohammed Abdul Muqeet 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 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!
Mohammed Abdul Muqeet 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900