【问题标题】:How to make print of web page particular area contains with charts?如何打印包含图表的网页特定区域?
【发布时间】:2012-02-14 22:17:27
【问题描述】:

我在打印图表时遇到问题。

我使用 Microsoft 图表控件制作了一个包含一些控件和一个图表的网页。目前这个问题在 IE 8 和 Firefox 9.0.1 中都影响到我

当我使用 JavaScript 进行打印时,它会打印 div 中包含的所有控件,但图表控件未显示在同一 div 中的打印预览页面上。

【问题讨论】:

  • 你能更精确地分享一下打印图表的代码吗?您还在使用 Microsoft Chart Controls 或其他第 3 方图表工具吗?
  • 构建一个仅包含图表的页面,并在页面末尾添加 JavaScript print() 和 close() 方法。
  • 支持这样的问题而不等待它得到改进?如果您想对 OP 友好,请提供有关如何改进问题的有用提示。
  • 您要在哪个浏览器中打印?

标签: javascript asp.net browser printing charts


【解决方案1】:

如果您使用Microsoft Chart Controls,您可以尝试以下代码进行打印:

public 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();

}

来电:

PrintWebControl(Panel1);

为您提供所需图表的打印。

【讨论】:

  • 但问题是他正在尝试打印嵌入了此类控件的页面。我认为他的问题是为什么它没有出现。
  • Script参数的内容是什么?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-11
  • 2016-09-19
  • 1970-01-01
相关资源
最近更新 更多