有关如何以PDF格式打印生成的图表的任何信息?它们在屏幕上看起来很棒,但最终用户希望打印它们并根据需要进行归档。

有帮助吗?

解决方案

从MSDN下载Chart Control示例。有几个如何打印的样本。要获得PDF,您需要PDF打印驱动程序。

http://code.msdn.microsoft.com /mschart/Release/ProjectReleases.aspx?ReleaseId=1591

查看\ WinSamples \ ChartFeatures \ Printing \

简单的方法是:

using System.Windows.Forms.DataVisualization.Charting;
...

// Show Page Setup dialog
chart1.Printing.PageSetup();

// Print preview chart
chart1.Printing.PrintPreview();

// Print chart (without Printer dialog)
chart1.Printing.Print(false);

...

其他提示

我正在寻找一种方法来实现这一目标并找到了winforms的答案

这是我获得asp:图表打印的方式

在网页上添加javascript:

<script type="text/javascript" language="javascript">
    function printChart() {

    var html = '<HTML>\n<HEAD>\n';
    html += '<link rel="stylesheet" type="text/css" href="../../../Styles/print.css" media="print"> \n';

    html += '\n</HEAD>\n<BODY>\n';
    html += '\n<div>';

    var printReadyElement = document.getElementById("printChart");

    if (printReadyElement != null) {
        html += printReadyElement.innerHTML;
    }
    else {
        alert("Trouble printing Chart");
        return;
    }

    html += '\n</div>';

    html += '\n</BODY>\n</HTML>';

    var printWin = window.open("", "printSpecial");
    printWin.document.open();
    printWin.document.write(html);
    printWin.document.close();

    printWin.print();

}

这与输入按钮

相关联
<input type="button" value="Print" onclick="printChart()" style="width:99px; height:26px;" />

下一步是向web.config添加元素

<appSettings> 
   <add key="ChartImageHandler" value="storage=memory;timeout=20;deleteAfterServicing=false;" />
</appSettings>

system.web 标记下

    <httpHandlers>      
        <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" />
    </httpHandlers>

system.webServer

<handlers>
  <remove name="ChartImageHandler">
  <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</handlers>

所以我在使用JavaScript函数PrintPage()时遇到了同样的问题; 它会打印网页,但不包括asp.net图表控件。您可以看到图表的边框,但不能看到数据。所以我解决这个问题的方法是移动用于在updatePanel之外调用我的printPage()函数的按钮,它可以工作。

希望这有助于某人。

<asp:Button runat="server" ID="btnPrint" OnClick="btnPrint_Click" CssClass="Floater" Text="Print Customer Report" Visible="True" />

<script>
    function PrintPage() {

        window.print();
    }
</script>

protected void btnPrint_Click(object sender, EventArgs e)
    { 
        ScriptManager.RegisterStartupScript(Page, GetType(), "JsStatus", "PrintPage();", true);
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top