我想将Crystal report
直接打印到打印机。目前我正在导出PDF
。但我的客户想要直接转到打印机。如何在单击“打印”按钮时显示Print Dialog
以将报告直接打印到打印机。
我想提一下:我正在为我的项目使用C#和asp.net。
谢谢。
答案 0 :(得分:2)
尝试以下代码
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();
}
您必须使用数据库的凭据更改“用户名”和“密码”。
修改强>
此代码仅可用于服务器端打印。
答案 1 :(得分:0)
没办法; Cristal Report Viewer用于显示和浏览报告 它从不显示所有报告页面 它没有直接打印的按钮或方法。
您可以直接导出PDF格式的报告,这样用户就不会看到报告查看器,打印变为一键操作。
答案 2 :(得分:0)
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; }