How to Generate Barcode on PrintOrderDetails in OrderController ?

5 months ago
i use this code
using (MemoryStream memoryStream = new MemoryStream())
            {
                using (Bitmap bitmap = new Bitmap(orderId.ToString().Length * 40, 80))
                {
                    using (Graphics graphics = Graphics.FromImage(bitmap))
                    {
                        Font ofont = new Font("IDAutomationHC39M", 16);
                        PointF point = new PointF(2f, 2f);
                        SolidBrush whiteBrush = new SolidBrush(Color.White);
                        graphics.FillRectangle(whiteBrush, 0, 0, bitmap.Width, bitmap.Height);
                        SolidBrush blackBrush = new SolidBrush(Color.Black);
                        graphics.DrawString("*" + orderId.ToString() + "*", ofont, blackBrush, point);
                    }
                    bitmap.Save(memoryStream, ImageFormat.Jpeg);

                    ViewBag.BarcodeImage = "data:image/png;base64," + Convert.ToBase64String(memoryStream.ToArray());
                }
            }
but only string generate not barcode.....
5 months ago
use this code for bar-code Generate -
-first we install Barcodelib nuget package (https://github.com/barnhill/barcodelib)in Nop.Web and then write this code in PrintOrderDetails method of OrderController ,

using (MemoryStream memoryStream = new MemoryStream())
            {
                Barcode b = new Barcode();
                Image img = b.Encode(TYPE.CODE39, "123456789101" , Color.Black, Color.White, 310, 90);
                {
                    img.Save(memoryStream, ImageFormat.Jpeg);
                    ViewBag.CODE39 = "data:image/png;base64," + Convert.ToBase64String(memoryStream.ToArray());
                }
            }

and then pass viewbag in order details.cshtml view lick that <img src="@ViewBag.CODE39" />