'Printing Crystal Report on Client Side in ASP.NET C#

I created an ASP.NET application where I print a Crystal Report report. The problem is that the report is printed at the Server Printer, and as it is a Web Application I need it to get printed at the client machine.

I am using the method PrintToPrinter(1, false, 0, 0) in order to print it without a crystal report viewer.

Does anybody knows if there is a way to have it printed on the client side? If not; what do you recommend to generate reports on the client side for ASP.Net applications?



Solution 1:[1]

Best way is to design a "HTML printable version" of your page with a link calling :

javascript:window.print(); 

Solution 2:[2]

here is what you will need to do / try to get the report to print on the Client Machine

Below line opens up print dialog box to print without showing print preview

crystalReportViewer1.PrintReport();

Below line directly sends reportdocument to default printer.

oReportDocument.PrintToPrinter(1,true,0,0); 

Solution 3:[3]

The Crystal report viewer is a server side control, and it doesn't really provide an easy way to print to client. I have been able to achieve this in the past by exporting the report to PDF, then with a combination of an embedded PDF viewer and some JavaScript, print the PDF.

// On server side
// Export to PDF
Guid imageGuid = Guid.NewGuid();
string pdfName = String.Format(@"{0}{1}{2}.pdf", pdfPath, reportName, imageGuid);
// expport to unique filename
report.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, pdfName);

// Display the pdf object in a literal control (mine's called pdfLiteral)
sb.AppendFormat("<object ID=\"pdfObject\" type=\"application/pdf\" data=\"{0}\" src=\"{0}\" style=\"width: 2px; height: 2px; ", pdfName);
sb.AppendLine("z-index:1; display: block; top: 0; left: 0; position: absolute; \">");
sb.Append("</object>");
pdfLiteral.Text = sb.ToString();
pdfLiteral.Visible = true;

// client side
// on document load call the printWithDialog function
 var code = function(){
    var pdf = document.getElementById('pdfObject');
    if (pdf == null)
        return;
    try {
        pdf.printWithDialog();
    }
    catch (err) {
        alert('Please Install Adobe Acrobat reader to use this feature');
    }
  };
// window onload, with delay
window.setTimeout(code, 1000);

See: https://stackoverflow.com/a/25994086/474702

Note: although this works well in Chrome, it only works in IE if the client has Acrobat reader installed as the default PDF viewer.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Amen Ayach
Solution 2 MethodMan
Solution 3 Community