首页 文章

为什么Crystal Reports PrintToPrinter方法如此慢

提问于
浏览
1

我正在使用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中运行代码还是在服务器上运行已部署的服务,我都会看到这种行为 .

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

打印到打印机需要很长时间或打印到Win2012打印服务器有问题吗?

谢谢?

2 回答

  • 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

  • 0

    此问题是由crystal 13基本运行时中的错误引起的 .

    如果使用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,看看这个问题是否已经解决 .

    EDIT

    慢速PrintToPrinter的问题现已解决,但SAP建议我们使用:

    report.ReportClientDocument.PrintOutputController.PrintReport(options);

    而不是PrintToPrinter,这将得不到进一步的发展 .

相关问题