0

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



    }

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

I get an error message that

The ShowDialog is not applicable with server

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

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

Shaharyar
  • 12,254
  • 4
  • 46
  • 66
barsan
  • 2,431
  • 16
  • 45
  • 62
  • You (and possibly your client) have to separate your thinking from "Windows development" to "Web development". What are you using to display the report on the ASP.NET Page? – Alexander Jul 02 '13 at 09:08
  • i am using reportviewer to show the report – barsan Jul 02 '13 at 09:27
  • Does this help? http://stackoverflow.com/questions/6465155/asp-net-crystal-report-viewer-print-button-not-working-in-asp-net – Alexander Jul 02 '13 at 09:41

1 Answers1

0

Java Script:

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