如何用Javascript打印Crystal报表?

时间:2013-07-02 08:45:06

标签: c# javascript asp.net crystal-reports

我在Crystal报表13上开发了一个Crystal Report,但我必须部署它的服务器有Crystal Report 10.我的客户希望将水晶报表直接打印到他们的打印机。他们不想要任何PDF,但现在它正在以PDF格式导出。然后在Stackoverflow朋友的帮助下,我编写了下面的代码,现在要求打印。我的代码如下:

CrystalDecisions.CrystalReports.Engine.ReportClass clsReport = new CrystalDecisions.CrystalReports.Engine.ReportClass();

protected void Button3_Click(object sender, EventArgs e)
{
    System.Windows.Forms.PrintDialog dialog1 = new System.Windows.Forms.PrintDialog();



    dialog1.AllowSomePages = true;
    dialog1.AllowPrintToFile = false;
    dialog1.ShowDialog();


    if (dialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        int copies = dialog1.PrinterSettings.Copies;
        int fromPage = dialog1.PrinterSettings.FromPage;
        int toPage = dialog1.PrinterSettings.ToPage;
        bool collate = dialog1.PrinterSettings.Collate;


        clsReport.PrintOptions.PrinterName = dialog1.PrinterSettings.PrinterName;
        clsReport.PrintToPrinter(copies, collate, fromPage, toPage);



    }

此代码允许从打印对话框进行打印,但是当我将此系统部署到以下服务器时: Windows Server 2008 R2 Enterprise

我收到一条错误消息

The ShowDialog is not applicable with server

所以,现在我想要一个允许从客户端打印页面的Javascript代码。但我不知道该怎么做。以及我如何隐藏Javascript打印页面上的按钮:window.print();

你的帮助将是最明显的。 我想提一下:我的系统是一个Web应用程序,使用ASP.Net,C#

1 个答案:

答案 0 :(得分:0)

Java脚本:

    function printCrystal() {            
        var printContent = document.getElementById('printReady');            
        var windowUrl = 'about:blank';
        var uniqueName = new Date();
        var windowName = 'Print' + uniqueName.getTime();
        var printWindow = window.open();
        printWindow.document.write('<HTML><HEAD></HEAD><BODY>'+printContent.innerHTML+'</BODY></HTML>');
        printWindow.focus();
        printWindow.print();
        printWindow.close();
    }

要打印的DIV标签:

<div id="printReady" class="ReportViewerContainerStyle">
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true"
            OnNavigate="CrystalReportViewer1_Navigate" HasCrystalLogo="False" HasToggleGroupTreeButton="False"
            Width="350px" HasToggleParameterPanelButton="False" ToolPanelView="None" Height="50px"
            EnableDrillDown="False" EnableParameterPrompt="False" />
    </div>