我想直接将我的Crystal报表
打印到打印机上。目前我已经导出为PDF
。但我的客户希望直接将其发送到打印机。如何在单击“打印”按钮时显示打印对话框
,以直接将报表打印到打印机上。
需要说明的是:我正在使用C#和asp.net进行项目开发。
谢谢。
我想直接将我的Crystal报表
打印到打印机上。目前我已经导出为PDF
。但我的客户希望直接将其发送到打印机。如何在单击“打印”按钮时显示打印对话框
,以直接将报表打印到打印机上。
需要说明的是:我正在使用C#和asp.net进行项目开发。
谢谢。
尝试以下代码
private void Button1_Click(object sender, EventArgs e)
{
CrystalReport1 report1 = new CrystalReport1();
PrintDialog dialog1 = new PrintDialog();
report1.SetDatabaseLogon("username", "password");
dialog1.AllowSomePages = true;
dialog1.AllowPrintToFile = false;
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;
report1.PrintOptions.PrinterName = dialog1.PrinterSettings.PrinterName;
report1.PrintToPrinter(copies, collate, fromPage, toPage);
}
report1.Dispose();
dialog1.Dispose();
}
编辑
此代码仅适用于服务器端打印。
在PrintButton_click事件中添加以下代码:
//show Print Dialog
PrintDialog printDialog = new PrintDialog();
DialogResult dr = printDialog.ShowDialog();
if (dr == DialogResult.OK)
{
ReportDocument crReportDocument = (ReportDocument)CrystalReportViewer1.ReportSource;
System.Drawing.Printing.PrintDocument printDocument1 = new System.Drawing.Printing.PrintDocument();
//Get the Copy times
int nCopy = printDocument1.PrinterSettings.Copies;
//Get the number of Start Page
int sPage = printDocument1.PrinterSettings.FromPage;
//Get the number of End Page
int ePage = printDocument1.PrinterSettings.ToPage;
crReportDocument.PrintOptions.PrinterName =printDocument1.PrinterSettings.PrinterName;
//Start the printing process. Provide details of the print job
crReportDocument.PrintToPrinter(nCopy, false, sPage, ePage);
// Form_Printerd = true; }
// 表单打印机已连接;不可能;Crystal Report Viewer 的目的是用于显示和浏览报告。
它从来不会显示所有报告页面。
它没有直接打印的按钮或方法。
相反,您可以直接将报告导出为PDF格式,这样用户就看不到报告查看器,打印变成了一键操作。