如何打印Crystal报表使用Javascript? [英] How to print Crystal report with Javascript?

查看:195
本文介绍了如何打印Crystal报表使用Javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个水晶报表的Crystal报表13开发的,但在那里我将其部署到服务器有水晶报表10.我的客户要打印的水晶报表直接到他们的打印机。他们不希望任何PDF但现在它被出口为PDF格式的罚款。然后用#1朋友的帮助我写了下面的code,现在它要求打印。我的code是如下:

I have a Crystal Report developed on Crystal report 13 but the server where I have to deploy it has Crystal Report 10. My client want to print the crystal report direct to their printer. They dont want any PDF but now it is exporting as PDF fine. Then with the help of Stackoverflow friend I wrote the below code and now its asking for print. My code is as below:

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



    }

这code允许从打印对话框中选择打印,但是当我部署该系统,服务器是:的Windows Server 2008 R2企业版

this code allows to print from a print dialog box but when I deploy this system to the server which is : Windows Server 2008 R2 Enterprise

我收到一条错误消息,

ShowDialog的不适用与服务器

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

So, now I want a Javascript code which can allow to print the page from Client side also. But I dont know how to do it. And how I can hide the button on the page from Javascript Printing: window.print();

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

Your help will be most appreciable. I would like to mention: My system is a Web Application, Using ASP.Net, C#

推荐答案

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 Tag to Print:

<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>

这篇关于如何打印Crystal报表使用Javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆