如何从ASP.NET CrystalReport打印在客户端打印机 [英] How to Print from ASP.NET CrystalReport on client side printer

查看:297
本文介绍了如何从ASP.NET CrystalReport打印在客户端打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将客户端的打印机上打印从CrystalReport(ASP.NET)报告。

How do I print report from CrystalReport (ASP.NET) on a client side printer.

推荐答案

您有两种选择:


  1. 设置的打印模式,以ActiveX或PDF,并保留Crystal报表查看器工具栏来处理它。

  2. 创建在iframe的PDF,并用JavaScript触发打印命令。

要简化用户必须安装在每个客户端我的隐藏PDF选项和一个单独的按钮继续打印到客户端的内容。

To simplify what the users had to install on each client I went with the hidden pdf option and a separate button to print to client.

在aspx页面我有一个asp的文字,我与1px的PDF格式嵌入式对象x 1像素的填充,所以它不是对用户可见。然后在页面加载调用printToPrinter方法​​。

On the aspx page I have an asp literal that I populate with the pdf embeded object at 1px x 1px so it isn't visible to the user. Then on pageload call the printToPrinter method.

// 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
// ...
// Display the pdf object 
_sb.AppendFormat("<object ID=\"pdfObject\" type=\"application/pdf\" data=\"{0}\" src=\"{0}\" style=\"width: {1}; height: {2}; ", _pdf2Name, _width, _height);
_sb.AppendLine("z-index:1; display: block; border: 1px solid #cccccc; top: 0; left: 0; position: absolute;-+ \">");
_sb.Append("</object>");
pdfLiteral.Text = _sb.ToString();
pdfLiteral.Visible = true;

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

这篇关于如何从ASP.NET CrystalReport打印在客户端打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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