2

I am using Crystal Reports, version 13, from inside visual studio 2010. I have a print server that is running Windows 2012. I dynamically set printer at run time, because I have about 30 printers that a report can go to. All these printers are configured on the Print Server.

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);
}

When I call the PrintToPrinter method:

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

It takes up to two and a half minutes to execute. I see this behavior whether I run the code in Visual Studio, or as a deployed service on a server.

We recently upgraded our services servers, and our print servers to windows 2012. Before, our services server was Windows 2008, and our print server was Windows 2003. We did not have this problem with that set up.

Has anyone experienced problems with printing to a printer taking a long time, or problems printing to a Win2012 Print Server?

Thanks?

essedbl
  • 520
  • 1
  • 7
  • 19

2 Answers2

5

Use

_report.ReportClientDocument.PrintOutputController.PrintReport(popt); 

instead of _report.PrintToPrinter, it is 5-10x faster. My code example:

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

Tested on CR 13.06., PrintToPrinter took ~3800 miliseconds while PrintReport only ~320

mshwf
  • 7,009
  • 12
  • 59
  • 133
Ramunas
  • 1,015
  • 1
  • 12
  • 19
1

This problem is caused by a bug in the crystal 13 basic runtime.

Setting the printer name is ignored if the report has been saved with the no printer option. So, the developer has to assign the entire PrinterSettings property of the report document. This is where the delay occurs.

// 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);

I had upgraded from 10.5 (basic 2008) which printed very quickly, but had to undergo a difficult rollback because of this (unacknowledged) bug.

I am currently researching the sp 10 from Crystal to see if this issue has been resolved.

EDIT

The issue with slow PrintToPrinter has now been resolved, however SAP have recommended we use:

report.ReportClientDocument.PrintOutputController.PrintReport(options);

instead of PrintToPrinter, which will get no further development.

reckface
  • 5,678
  • 4
  • 36
  • 62
  • ,When i use the above line , i get clientdoc.iscdreportcleintdocument does not contain definition for 'PrintOutputController' and no extension method 'PrintOutputController' acception argument error. Can You Please help! – Ameena Apr 08 '15 at 17:18
  • Are you using the correct version of the runtime? That property is the version 13. See http://scn.sap.com/docs/DOC-7824 – reckface Apr 08 '15 at 18:17