我想将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();
}
您必须使用数据库的凭据更改“用户名”和“密码”.
编辑
此代码仅可用于服务器端打印.