c# - 在 Web 应用程序中使用条码渲染框架生成的条码下的条码编号

标签 c# asp.net printing barcode

以下是我之前的问题,它运行良好并生成了条形码。 My previous Question

现在,我只想在这个条形码(图像)下写入字符(形成条形码)。我怎样才能做到这一点?我正在使用 Barcode Rendering Framework 生成条形码。请帮忙。

我可以通过取一个面板并添加图像和文本(条形码字符)并打印面板来做到这一点吗??

最佳答案

我是通过使用 asp 面板完成的,我在其中添加了创建的条形码图像。在那下面我添加了字符串,即我的条形码字符。然后使用打印助手功能我可以打印它们。 以下是我将图像和文本添加到面板的代码。

Code39BarcodeDraw barcode39 = BarcodeDrawFactory.Code39WithoutChecksum;
           // Panel pnl = new Panel();
            Label str = new Label();
            str.Text="SER1012308131";
           // System.Drawing.Image img = barcode39.Draw("SER1012308131", 40);
            //string path = Server.MapPath("~/Uploads/") + img+".jpeg";
            string path = @"~/Uploads/abcd.jpeg";
          //  img.Save(path);
            Image imgg = new Image();
            imgg.ImageUrl=path;
            pnlpnl.Width = Unit.Pixel(300);
            pnlpnl.Height = Unit.Pixel(45);
            pnlpnl.Controls.Add(imgg);
            pnlpnl.Controls.Add(str);
            Session["ctrl"] = pnlpnl;
            ClientScript.RegisterStartupScript
                (this.GetType(), "onclick", "<script language=javascript>window.open('Print.aspx','PrintMe','height=45px,width=300px,scrollbars=1');</script>");

打印辅助函数。

public PrintHelper()
    {
    }

    public static void PrintWebControl(Control ctrl)
    {
        PrintWebControl(ctrl, string.Empty);
    }

    public static void PrintWebControl(Control ctrl, string Script)
    {
        StringWriter stringWrite = new StringWriter();
        System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
        if (ctrl is WebControl)
        {
            Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;
        }
        Page pg = new Page();
        pg.EnableEventValidation = false;
        if (Script != string.Empty)
        {
            pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
        }
        HtmlForm frm = new HtmlForm();
        pg.Controls.Add(frm);
        frm.Attributes.Add("runat", "server");
        frm.Controls.Add(ctrl);
        pg.DesignerInitialize();
        pg.RenderControl(htmlWrite);
        string strHTML = stringWrite.ToString();
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Write(strHTML);
        HttpContext.Current.Response.Write("<script>window.print();</script>");
        HttpContext.Current.Response.End();
    }

关于c# - 在 Web 应用程序中使用条码渲染框架生成的条码下的条码编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18401132/

相关文章:

c# - Windows UI 中的 ListView 缓存?

c# - HttpClient 从不在 IIS 上发送请求

c# - 在 Winform 应用程序中打印

c++ - 什么相当于C/C++中C#的PrintDocument?

c# - 在一个 SqlCe 命令中创建多个表不起作用

c# - 突出显示所有字段 Nest ElasticSearch

c# - 检查字符串是否在两个字母之间

asp.net - 使用响应对象生成 PDF 时的预加载器

javascript - 使用 javascript 在 ASP.NET 中的列表框之间移动项目,然后在服务器端访问结果的最佳方法

java - 打印对象数组时遇到问题