我在 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/