[英]How to display the print dialog box for crystal report viewer in wpf
[英]How to show print dialog in Crystal Report?
我想直接将Crystal report
打印到打印机。 目前,我正在导出为PDF
。 但是我的客户希望将此直接转到打印机。 单击“打印”按钮时如何显示“ Print Dialog
”以将报告直接打印到打印机。
我想提到:我在项目中使用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();
}
您将必须使用数据库的凭据更改“用户名”和“密码”。
编辑
此代码只能用于服务器端打印。
没门; Cristal Report Viewer用于显示和浏览报告。
它从不显示所有报告页面。
它没有用于直接打印的按钮或方法。
相反,您可以直接将报告导出为PDF,这样用户就不会看到Report Viewer,并且打印成为一键式操作。
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; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.