本文介绍了单击打印按钮时图像无法打印?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Print.aspx.cs
Print.aspx.cs
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(); PaperSize p = null; PrintDocument pd = new PrintDocument(); pd.PrinterSettings.DefaultPageSettings.Landscape = true; pd.DefaultPageSettings.PaperSize = p; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Write(@"<link href='/Style1.css' rel='stylesheet' type='text/css' />"); HttpContext.Current.Response.Write(strHTML); HttpContext.Current.Response.Write("<script>window.print();</script>"); HttpContext.Current.Response.End(); } protected void Print_Button_Click(object sender, EventArgs e) { PrintInvoice.PrintWebControl(Panel1); }添加了 pre 标签。 [/编辑]
推荐答案
更多推荐
单击打印按钮时图像无法打印?
发布评论