0

我有一个在 Crystal Report 13 上开发的 Crystal Report,但我必须部署它的服务器有 Crystal Report 10。我的客户希望将 Crystal Report 直接打印到他们的打印机上。他们不想要任何 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#

4

1 回答 1

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>
于 2013-07-02T08:55:58.103 回答