2014-01-15 291 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