首页 文章

Crystal报表运行时是否支持Visual Studio支持分配打印机?

提问于
浏览
0

我已经使用Crystal报表基本运行时2008(10.5)超过3年了 . 我大约一年前升级到Microsoft Visual Studio(13)的最新开发人员版本,并安装了Service Pack 2.但我发现如果报表已经有一个打印机名称,在报表文档上设置PrintOptions.PrinterName无效 . 概述了herehere .

// This is the old and reliable way - didn't work for version 13
Settings = new PrinterSettings();
Settings.PrinterName = "HP Printer";
_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,我仍然使用visual studio 2013 .

有没有人对更新的服务包(9或10)有任何经验?

他们的修复错误没有提到这个问题已被修复 . 我正在考虑再次升级以解决版本10.5中的一些缺失功能 .

1 回答

  • 1

    我看了SAP will not be fixing anything to do with PrintToPrinter

    打印机分配的问题(错误)仍然存在,更改的是分配整个打印机设置对象不再需要2-3分钟 . 此外,现在有更好的方法可以按照SAP的建议进行打印 .

    因此,如果打印机名称分配没有“接受”,我会尝试通过仅使用接受PrinterSettings的PrintToPrinter重载来避免它:

    // Attempt to assign just the printer name
    _report.PrintOptions.PrinterName = Settings.PrinterName;
    
    // Check if the name change worked, if not, PrintToPrinter with the settings object
    if(_report.PrintOptions.PrinterName != Settings.PrinterName)
        _report.PrintToPrinter(Settings, new PageSettings(), false); // print with settings
    else
        _report.PrintToPrinter(Settings.Copies, Settings.Collate, 0, 0); // print with printer name
    

    SAP建议使用_report.ReportClientDocument.PrintOutputController.PrintReport(options)而不是_report.PrintToPrinter(...) . 我的可重复测试表明,这种方法至少快三倍了! (我使用了stopWatch,并反复打印了相同的18页静态报告.PrintToPrinter每次大约需要9秒才能进行假脱机,而下面的方法平均为3秒)

    // Create the printer options
    var options = new PrintReportOptions
    {
        PrinterName = Settings.PrinterName,
        Collated = Settings.Collate,
        NumberOfCopies = Settings.Copies,
        JobTitle = _report.Name,       
    };
    // pass the options to the print method
    _report.ReportClientDocument.PrintOutputController.PrintReport(options);
    

相关问题