我正在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);
}


当我调用PrintToPrinter方法时:

crReportDocument.PrintToPrinter(printerSettings,pSettings,false,PrintLayout);

执行最多需要两分半钟。无论我是在Visual Studio中运行代码,还是在服务器上作为已部署的服务运行,我都会看到这种现象。

我们最近将服务服务器和打印服务器升级到Windows2012。之前,我们的服务服务器是Windows 2008,打印服务器是Windows2003。该设置没有此问题。

有没有人经历过长时间打印到打印机上的问题,或在Win2012打印服务器上打印的问题?

谢谢?

最佳答案

使用

_report.ReportClientDocument.PrintOutputController.PrintReport(popt);


而不是_report.PrintToPrinter,速度提高了5-10倍。
我的代码示例:

CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions popt = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();
popt.PrinterName = printerSettings.PrinterName;
_report.ReportClientDocument.PrintOutputController.PrintReport(popt);


在CR 13.06上进行了测试,PrintToPrinter花费了大约3800毫秒,而PrintReport仅花费了〜320

07-24 21:42