I'm a C# developer and I need to use Crystal Report for my editions.
The problem is that it only prints in portrait. When I try to change the print settings, they are ignored. If, for example, I choose "landscape" in the printer settings, it will still print in portrait.

I've found a lot of topics about this but no working answer. In particular, I saw that you could uncheck "optimized for display", but that doesn't change anything.
I tried to cheat by creating a "print" button and coding it myself to force the parameters:
private void OnPrintButtonClick(object sender, RoutedEventArgs e)
{
PrintDialog PrintD = new PrintDialog();
Nullable<Boolean> print = false;
try
{
print = PrintD.ShowDialog();
}
catch (Exception exc)
{
MessageBox.Show("Imprimante non trouvée: " + exc.Message, "Erreur");
}
if (print == true)
{
PrintQueue printQueue = PrintD.PrintQueue;
report.PrintOptions.PrinterName = printQueue.FullName;
Debug.WriteLine("Printer Name: " + printQueue.FullName);
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
printerSettings.PrinterName = printQueue.FullName;
report.PrintToPrinter(1, false, 0, 0);
}
}
It works on most printers, but today I have a problem with a client where printing causes a "System.Runtime.InteropServices.COMException: invalid printer name" error.
The ideal would be for the application to work "natively" with the settings the user chooses, without having to force anything, I guess.
I'm on CR 13.0.22 and I've run out of ideas.
I assume that you can get Page Orientation from print dialog with PrintD.PrintTicket.PageOrientation.
How about setting this value to report.PrintOptions.PaperOrientation before calling PrintToPrinter function.
Here is a code example below that you might try.
if (print == true)
{
PrintQueue printQueue = PrintD.PrintQueue;
report.PrintOptions.PrinterName = printQueue.FullName;
System.Drawing.Printing.PrinterSettings printerSettings = new System.Drawing.Printing.PrinterSettings();
printerSettings.PrinterName = printQueue.FullName;
var orientation = PrintD.PrintTicket.PageOrientation;
if (orientation == PageOrientation.Landscape)
{
report.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
}
if (orientation == PageOrientation.Portrait)
{
report.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait;
}
report.PrintToPrinter(1, false, 0, 0);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With