c# - Crystal Reports 打印纵向而不是横向

标签 c# crystal-reports

我在 SAP Crystal Reports 14.1.4.1327 中创建了一个非常简单的测试报告(.rpt 文件)。我在页面设置中将页面方向设置为横向。如果我从 Crystal Reports Designer 打印我的文档,它可以正确地横向打印。 我需要从 C# 应用程序打印报告。我为 .Net 13.0.6.1027 使用 SAP Crystal Reposrts 运行时引擎

ReportDocument rp = new ReportDocument();
rp.Load(path_to_my_report_file);
rp.PrintOptions.PrinterName = printerName;
rp.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
rp.PrintToPrinter(0, false, 0, 2);

它始终以纵向打印。我不知道为什么它不起作用。

我还尝试了 PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, bool reformatReportPageSettings) 方法并设置了

...
System.Drawing.Printing.PrinterSettings printersettings = new   System.Drawing.Printing.PrinterSettings();
printersettings.DefaultPageSettings.Landscape = true
...
rp.PrintToPrinter(printersettings, pageSettings, false);

但它也不起作用。

如何横向打印报表?我无法修改打印机驱动程序配置,因此解决方案必须基于 C# 或 .rpt 文件。

===EDIT===

我还在另一台打印机 (RICOCH) 上测试了我的外壳,它可以正确地横向打印。我使用 ZEBRA ZTC S4M-200dpi ZPL,它打印的是肖像而不是风景。所以 Zebra 驱动程序可能与 .Net 不完全兼容。

===EDIT===

我注意到如果 PaperSize 设置正确,Zebra 可以正确打印报告。所以下面的代码有效:

...
System.Drawing.Printing.PrinterSettings printersettings = new   System.Drawing.Printing.PrinterSettings();
printersettings.DefaultPageSettings.Landscape = true
System.Drawing.Printing.PageSettings pageSettings = new System.Drawing.Printing.PageSettings();
...
pageSettings.PaperSize = new System.Drawing.Printing.PaperSize("name", 400, 600);
rp.PrintToPrinter(printersettings, pageSettings, false);

其中 400 是宽度,600 是纵向高度,以百分之一英寸为单位。因此 C# 应用程序需要从报告中检索页面宽度、页面高度和页面方向。我不知道如何检索这些参数。我问一下here

最佳答案

这对我有用:

            cryRpt.PrintOptions.PaperSource = PaperSource.Auto;
            cryRpt.PrintOptions.PaperSize = PaperSize.DefaultPaperSize;
            cryRpt.PrintOptions.PaperOrientation = PaperOrientation.Landscape;

关于c# - Crystal Reports 打印纵向而不是横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29800187/

相关文章:

java - CR4E Crystal Reports保存修改后的ChartObject

c# - Crystal 报表图表细节抑制

reporting-services - 有没有办法在 Crystal 报告或 SSRS 中显示气球工具提示

delphi - 有没有办法从流加载 Crystal Report 9.0 文件?

c# - 是否可以在 app.config 文件中设置自定义属性?

c# - 使用表达式在 EF4 中渴望加载多对多?

c# - Facebook SDK 在 Windows 10 应用程序上加载时出错(XAML、C#)

c# - 在自定义 JsonConverter 中,如何确定 Utf8JsonReader 数字标记是小数还是长整型?

c# - 如何在用户 session 被锁定时注销用户

c# - 数据库连接导致 CrystalReports ReportDocument 内存泄漏