How can we set the settings for printing in the new print preview of windows 11?

Alessandro 15 Reputation points
2023-07-26T15:02:55.4766667+00:00

We are struggling with the new print preview with windows 11. Before the print we are changing some settings based on some configuration of our program. These settings are applied to the old print dialog of windows, but on the new one our settings are ignored.

I wrote a small example. I just want to have the orientation in Landscape (German: Querformat):

        private void PrintBt_Click(object sender, RoutedEventArgs e)
        {
            // Create the print dialog object and set options
            PrintDialog pDialog = new PrintDialog();
            pDialog.PrintTicket.PageOrientation = System.Printing.PageOrientation.Landscape;
            pDialog.PageRangeSelection = PageRangeSelection.AllPages;
            pDialog.UserPageRangeEnabled = true;
            // Display the dialog. This returns true if the user presses the Print button.
            Nullable<Boolean> print = pDialog.ShowDialog();            
        }

We tried with the .NET 6 and with .NET Framework 4.8 and in both cases it's not working.

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,971 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
10,113 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jiale Xue - MSFT 47,501 Reputation points Microsoft Vendor
    2023-07-27T07:09:31.9066667+00:00

    Hi @Alessandro, Welcome to Microsoft Q&A.

    Updated in WPF:

    private void InvokePrint(object sender, RoutedEventArgs e)
    {
        // Create the print dialog object and set options
        PrintDialog pDialog = new PrintDialog();
        PrintTicket printTicket = pDialog.PrintTicket;
        printTicket.PageOrientation = PageOrientation.Landscape; // Set the print orientation here
        pDialog.PageRangeSelection = PageRangeSelection.AllPages;
        pDialog.UserPageRangeEnabled = true;
        // Display the dialog. This returns true if the user presses the Print button.
        Nullable<Boolean> print = pDialog.ShowDialog();
        if (print == true)
        {
        }
    }
    

    Use PrintDialog in C# winform.

    You can modify printer settings using PrinterSettings.

    The following code modifies printerSettings.DefaultPageSettings directly. If you choose a printer other than the default, you may have to modify the code location. It can be directly placed inside if (printDialog1.ShowDialog() == DialogResult.OK).

    private void button1_Click(object sender, EventArgs e)
    {
        // Get the selected printer settings from the PrintDialog
        PrinterSettings printerSettings = printDialog1.PrinterSettings;
        // Set the default printer settings
        printerSettings.DefaultPageSettings.Landscape = true;
        // Create the PrintDialog object
        // Show the print dialog
        if (printDialog1.ShowDialog() == DialogResult.OK)
        {
            // Create the PrintDocument object
            PrintDocument printDocument = new PrintDocument();
            // Set the PrinterSettings for the PrintDocument
            printDocument.PrinterSettings = printerSettings;
            // Set the PrintPage event handler for the PrintDocument
            printDocument.PrintPage += PrintDocument_PrintPage;
            // Start the printing process
            printDocument.Print();
        }
    }
    private void PrintDocument_PrintPage(object sender, PrintPageEventArgs e)
    {
        // Add your printing logic here
        // This event is triggered for each page that needs to be printed
    }
    

    User's image

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.