4
votes

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

1
Seems like printer setup issue. Can you check page orientation settings in the printer ?Amal Dev
Regardless of what is set in orientation settings in the printer, Crystal Designer prints in landscape orientation, C# prints in portrait orientation.Mariusz

1 Answers

0
votes

This works for me:

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