ess*_*dbl 2 c# printing crystal-reports
我正在使用 Visual Studio 2010 内部的 Crystal Reports 版本 13。我有一台运行 Windows 2012 的打印服务器。我在运行时动态设置打印机,因为我有大约 30 台打印机可以发送报表。所有这些打印机都在打印服务器上进行配置。
PrintDocument pDoc = new PrintDocument();
PrintLayoutSettings PrintLayout = new PrintLayoutSettings();
PrinterSettings printerSettings = new PrinterSettings();
printerSettings.PrinterName = pq.printerName;
PageSettings pSettings = new PageSettings(printerSettings);
crReportDocument.PrintOptions.DissociatePageSizeAndPrinterPaperSize = true;
crReportDocument.PrintOptions.PrinterDuplex = PrinterDuplex.Simplex;
OnMessageLogged(TraceEventType.Information, "PrePrint " + crReportDocument.PrintOptions.PrinterName);
WindowsImpersonationContext ctx = WindowsIdentity.Impersonate(IntPtr.Zero);
try
{
crReportDocument.PrintToPrinter(printerSettings, pSettings, false, PrintLayout);
OnMessageLogged(TraceEventType.Information, "Printed " + pq.printerName);
}
catch (Exception eprint)
{
OnMessageLogged(TraceEventType.Information, "****Failed to Print** to printer " + pq.printerName + " Exception " + eprint.ToString());
}
finally
{
// Resume impersonation
ctx.Undo();
OnMessageLogged(TraceEventType.Information, "Success Printing to " + pq.printerName);
}
Run Code Online (Sandbox Code Playgroud)
当我调用 PrintToPrinter 方法时:
crReportDocument.PrintToPrinter(printerSettings, pSettings, false, PrintLayout);
执行最多需要两分半钟。无论是在 Visual Studio 中运行代码,还是作为服务器上部署的服务,我都会看到这种行为。
我们最近将我们的服务服务器和打印服务器升级到了 windows 2012。之前,我们的服务服务器是 Windows 2008,我们的打印服务器是 Windows 2003。我们的设置没有这个问题。
有没有人遇到打印到打印机需要很长时间的问题,或者打印到 Win2012 打印服务器的问题?
谢谢?
用
_report.ReportClientDocument.PrintOutputController.PrintReport(popt);
Run Code Online (Sandbox Code Playgroud)
而不是_report.PrintToPrinter,它的速度提高了 5-10 倍。我的代码示例:
CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions popt = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();
popt.PrinterName = printerSettings.PrinterName;
_report.ReportClientDocument.PrintOutputController.PrintReport(popt);
Run Code Online (Sandbox Code Playgroud)
在 CR 13.06. 上测试,PrintToPrinter花费了 ~3800 毫秒,而PrintReport只有 ~320