以下是我之前的问题,它运行良好并生成了条形码。 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/