65.9K
CodeProject 正在变化。 阅读更多。
Home

使用 ASP.NET 打印斑马条码

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0投票)

2013 年 10 月 11 日

CPOL

1分钟阅读

viewsIcon

19087

使用 ASP.NET 打印斑马条码在互联网上很难找到关于如何从 ASP.NET 表单打印斑马条码的信息。是的,确实如此。

使用 asp.net 打印斑马条码

在互联网上很难找到关于如何从 ASP.NET 表单打印斑马条码的信息。
你通常能找到的是使用 Javascript 实现相同功能。从 Windows 应用程序实现起来也很容易。
 
问题:当你使用 Javascript 时,你必须将图像(条码)保存在 aspx 页面上,然后触发 Javascript 打印命令。这对于激光打印机来说效果很好,但在斑马打印机上存在问题,因为图像 会被生成,但我们无法扫描它。因此,如果你使用的是斑马打印机,生成的条码将毫无用处。
 
代码简单明了。
它允许你打印条码,并从 ASP.NET 访问斑马打印机。
 
1.       安装 .NET 上免费的字体“3 of 9 Barcode
2.       创建一个 ASP.NET 项目
3.        添加以下代码
 
 
public void Submit_Click(object sender, EventArgs e)
        {
            try
            {
                PrintDocument pd = new PrintDocument();
                pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
                // 设置打印机名称。
                //pd.PrinterSettings.PrinterName = "file://ns5/hpoffice
                //pd.PrinterSettings.PrinterName = "Zebra New GK420t"              
                pd.Print();
            }
            catch (Exception ex)
            {
                Response.Write("Error: " + ex.ToString());
            }
        }
        void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            Font printFont = new Font("3 of 9 Barcode", 17);
            Font printFont1 = new Font("Times New Roman", 9, FontStyle.Bold);

            SolidBrush br = new SolidBrush(Color.Black);

            ev.Graphics.DrawString("*texttodisplay*", printFont, br, 10, 65);
            ev.Graphics.DrawString("*texttodisplay*", printFont1, br, 10, 85);
          
        }



© . All rights reserved.