如何在客户端打印机上打印Crystal Report(ASP.NET)中的报告。
答案 0 :(得分:0)
您有两种选择:
为了简化用户在每个客户端上安装的内容,我使用了隐藏的pdf选项和一个单独的按钮来打印到客户端。
在aspx页面上,我有一个asp文字,我用1px x 1px的pdf embeded对象填充,因此用户看不到它。然后在pageload上调用printToPrinter方法。
// 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);