Print file with selected printer profile/page size

Spread the love

Question Description

I have a option that user can select the print option where it brings up the PrintDialogwhere user can select the already defined printer profile.

For this printer default paper size is A4 but selecting this profile it get change to A5.

enter image description here

I am using the below code which send the print task to correct printer but doesn’t pick up the correct paper size as it always print in A4. Am I missing anything here or is there alternate way of achieving this?

 using (var pd = new PrintDialog())
 {
   if (pd.ShowDialog() == DialogResult.OK)
      {
         var info = new ProcessStartInfo(filepath)
                    {
                        Arguments = "\"" + pd.PrinterSettings + "\"",
                        CreateNoWindow = true,
                        WindowStyle = ProcessWindowStyle.Hidden,
                        UseShellExecute = true,
                        Verb = "Print"
                    };
        Process.Start(info);
      }
  }

Practice As Follows

You should be able to specify the page settings using code like the following, which relies on PrintDocument from System.Drawing.Printing. If necessary, you can also define an event handler for the PrintPage event using the PrintDocument class:

PrintDocument pd = new PrintDocument();
//pd.PrintPage += new PrintPageEventHandler(handlePagePrint);
pd.PrinterSettings.PrinterName = "Printer name goes here";
// select the appropriate item from the PaperSizes collection
pd.DefaultPageSettings.PaperSize = pd.PrinterSettings.PaperSizes[0];

if (pd.PrinterSettings.IsValid)
{
    pd.Print();
}

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.