简体   繁体   中英

Crystal Reports prints portrait orientation instead of landscape

I created a very simple test report (.rpt file) in SAP Crystal Reports 14.1.4.1327. I set page orientation to landscape in Page Setup. If I print my document from Crystal Reports Designer it is printed properly in landscape. I require to print report from C# application. I uses SAP Crystal Reposrts runtime engine for .Net 13.0.6.1027

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);

It prints always in portrait orientation. I don't know why it does not work.

I also tried PrintToPrinter(PrinterSettings printerSettings, PageSettings pageSettings, bool reformatReportPageSettings) method and I set

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

but it also does not work.

How to print report in landscape? I can't modify printer driver configuration so solution must be based on C# or .rpt file.

===EDIT===

I tested my case also on another printer (RICOCH) and it prints properly in landscape. I uses ZEBRA ZTC S4M-200dpi ZPL and it prints portait instead of landscape. So maybe Zebra driver is not full compatible with .Net.

===EDIT===

I noticed that Zebra prints report properly if PaperSize is set properly. So following code works:

...
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);

Where 400 is width, 600 is high in portrait orientation in hundredths of an inch. So C# application needs to retrieve page width, page high and page orientation from report. I don't know how to retrieve these parameters. I ask about it here

This works for me:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM