Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to embedd data in barcode and string value with line break or space on a single barcode? I want to get the printed bar code on the basis of data entered in the PDF file. Following is the code I am using:
C#
string barCode = txtCode.Text;
         System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
         using (Bitmap bitMap = new Bitmap(barCode.Length * 40, 80))
         {
             using (Graphics graphics = Graphics.FromImage(bitMap))
             {
                 Font oFont = new Font("IDAutomationHC39M", 16);
                 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);
Posted
Updated 5-May-14 19:57pm
v2

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