【问题标题】:how to print barcode in asp.net?如何在asp.net中打印条形码?
【发布时间】:2014-06-11 08:47:20
【问题描述】:

我有一个 asp.net 网站,我想用 c# 打印一些条形码。我使用“IDAutomationHC39M”字体如下:

public static void PrintSmallBarcode(HtmlGenericControl divBarCode, string barCode)
    {
        System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
        using (Bitmap bitMap = new Bitmap(75, 18))
        {
            using (Graphics graphics = Graphics.FromImage(bitMap))
            {
                Font oFont = new Font("IDAutomationHC39M", 7);
                PointF point = new PointF(0, 0);
                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);
                imgBarCode.CssClass = "cssbarcode";
            }
        }
        div.Controls.Add(imgBarCode);
}

它可以工作,但条码质量低,我的条码阅读器设备无法读取它。我不能增加图像的大小,当然我看到很多比我的尺寸小的好的条形码。我用“free3of9.ttf”替换“IDAutomationHC39M”字体,但这个字体只画数字,没有条码线! 我怎样才能获得更好的条形码?

【问题讨论】:

    标签: c# asp.net printing barcode-printing


    【解决方案1】:

    这是条形码字体长期存在的问题;它们很大,而且扫描效果很差,因为打印机会尝试对条形进行抗锯齿处理。

    使用图像而不是字体来绘制条形码。有很多可用的包,例如Barcode Rendering Framework

    【讨论】:

      【解决方案2】:

      您可以使用其他数据来更改条码的大小。我使用keepautomationbarcode generator for asp.net在Visual C# ASP.NET 项目中创建条码图像。经过我的设置,我可以预览条码的大小。

      【讨论】:

      • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 1970-01-01
      • 1970-01-01
      • 2019-08-15
      相关资源
      最近更新 更多