2014-01-15 298 views
1

我在Visual Studio 2010中使用Crystal Reports版本13。我有一台运行Windows 2012的打印服务器。我在运行时动态设置打印机,因为我有报告可以打印的30台打印机。所有这些打印机都在打印服务器上配置。为什么Crystal Reports PrintToPrinter方法很慢

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,假,PrintLayout);

执行需要花费两分半钟的时间。无论我在Visual Studio中运行代码还是在服务器上部署服务,我都会看到这种行为。

我们最近将我们的服务服务器和我们的打印服务器升级到了Windows 2012.之前,我们的服务服务器是Windows 2008,而我们的打印服务器是Windows 2003.我们没有设置这个问题。

有没有人在打印到打印机需要很长时间或打印到Win2012打印服务器时遇到问题?

谢谢?

回答

0

此问题是由crystal 13 basic runtime中的一个错误引起的。

如果报告已使用no printer选项保存,则忽略设置打印机名称。因此,开发人员必须分配报告文档的整个PrinterSettings属性。这是延迟发生的地方。

// This is the old and reliable way - didn't work for version 13 
Settings = new PrinterSettings(); 
Settings.PrinterName = "HP Printer"; 
// you don't even need the PrinterSettings object in 10.5, just the printer name 
_report.PrintOptions.PrinterName = Settings.PrinterName; 
// for version 13 you have to assign the printer settings 
if(_report.PrintOptions.PrinterName != Settings.PrinterName) 
    _report.PrintToPrinter(Settings, new PageSettings(), false); 

我已经从10.5(基本2008),其印刷速度非常快,但不得不接受,因为这(未确认)错误的困难回滚升级。

我目前正在研究Crystal的sp 10以查看此问题是否已解决。

编辑

缓慢PrintToPrinter此问题现已得到解决,但是SAP已经建议我们使用:

report.ReportClientDocument.PrintOutputController.PrintReport(options);

代替PrintToPrinter,这将得不到进一步的发展。

+0

,当我使用上面的线,我得到clientdoc.iscdreportcleintdocument不包含“PrintOutputController定义'并且没有扩展方法'PrintOutputController'接受参数错误。你能帮忙吗? – Ameena

+0

您是否使用正确版本的运行时?该属性是版本13.请参阅http://scn.sap.com/docs/DOC-7824 – reckface

2

使用“_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