在ASP.NET C中打印客户端上的Crystal报表#

时间:2012-03-01 19:04:09

标签: c# asp.net printing crystal-reports client-side

我创建了一个ASP.NET应用程序,用于打印Crystal Report报表。问题是报告是在服务器打印机上打印的,因为它是一个Web应用程序,我需要它在客户端机器上打印。

我正在使用方法PrintToPrinter(1, false, 0, 0),以便在没有水晶报表查看器的情况下进行打印。

有人知道是否有办法在客户端打印?如果不;您建议在ASP.Net应用程序的客户端生成报告?

3 个答案:

答案 0 :(得分:0)

最好的方法是使用链接调用

设计页面的“HTML可打印版本”
javascript:window.print(); 

答案 1 :(得分:0)

以下是您需要执行的操作/尝试在客户端计算机上打印报告

下面的行打开打印对话框进行打印而不显示打印预览

crystalReportViewer1.PrintReport();

下面的行直接将reportdocument发送到默认打印机。

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

答案 2 :(得分:0)

Crystal报表查看器是服务器端控件,它实际上并不提供一种简单的方法来打印到客户端。我之前通过将报告导出为PDF,然后结合使用嵌入式PDF查看器和一些JavaScript来打印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);

请参阅:https://stackoverflow.com/a/25994086/474702

注意:虽然这在Chrome中运行良好,但只有在客户端安装了Acrobat Reader作为默认PDF查看器时才能在IE中使用。

相关问题