【问题标题】:Why is the Crystal Reports PrintToPrinter method so slow为什么 Crystal Reports PrintToPrinter 方法这么慢
【发布时间】:2014-01-15 22:18:30
【问题描述】:

我正在使用 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 打印服务器的问题?

谢谢?

【问题讨论】:

    标签: c# printing crystal-reports


    【解决方案1】:

    使用

    _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 毫秒

    【讨论】:

      【解决方案2】:

      这个问题是由水晶13基本运行时的一个bug引起的。

      如果使用无打印机选项保存报告,则忽略设置打印机名称。因此,开发人员必须分配报表文档的整个 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,它不会得到进一步的发展。

      【讨论】:

      • ,当我使用上述行时,我得到 clientdoc.iscdreportcleintdocument 不包含'PrintOutputController' 的定义并且没有扩展方法'PrintOutputController' 接受参数错误。你能帮忙吗!
      • 您使用的是正确版本的运行时吗?该属性是版本 13。请参阅 scn.sap.com/docs/DOC-7824
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多