Hello Team,
The system default print setting will be changing when my customer has used to print a document in my application. Attached the screenshot for the printer setting default screen.
I have used the below code to print my documents in my project, I need to use the below code and print my documents without change the system default printer setting.
In my project, I will print the image in the below code. Any have an idea please share how to print without change the system default print setting.
PrintDocument pd = new PrintDocument();
PrintController printController = new StandardPrintController();
pd.PrintController = printController;
pd.PrinterSettings.PrinterName = LabelPrinter.Text.ToString(); //Printer Name
pd.PrinterSettings.Copies = Convert.ToInt16(printqty);
pd.DefaultPageSettings.Landscape = false;
pd.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
pd.PrinterSettings.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
pd.PrintPage += (sndr, args) =>
{
System.Drawing.Image i = System.Drawing.Image.FromFile(FileName); //image
//Adjust the size of the image to the page to print the full image without loosing any part of the image.
System.Drawing.Rectangle m = args.MarginBounds;
//Logic below maintains Aspect Ratio.
if ((double)i.Width / (double)i.Height > (double)m.Width / (double)m.Height) // image is wider
{
m.Height = (int)((double)i.Height / (double)i.Width * (double)m.Width);
}
else
{
m.Width = (int)((double)i.Width / (double)i.Height * (double)m.Height);
}
//Calculating optimal orientation.
pd.DefaultPageSettings.Landscape = m.Width > m.Height;
pd.DefaultPageSettings.Landscape = false;
args.Graphics.DrawImage(i, m);
};
pd.Print();
Notes:
Code - C# windows application.
System - Windows 10.