Why is the Crystal Reports PrintToPrinter method so slow

13,718

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

Share:
13,718
essedbl
Author by

essedbl

Updated on June 15, 2022

Comments

  • essedbl
    essedbl almost 2 years

    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?