如何使用Javascript打印Crystal报告

本文关键字:Crystal 报告 打印 Javascript 何使用 | 更新日期: 2023-09-27 18:20:50

我有一个在Crystal Report 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#

如何使用Javascript打印Crystal报告

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>