Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am trying to change printer sittings using the below code, when press on button it is printing but printer sittings not changed , the printer it is shared printer and i gave permissions for user to change the sittings.any idea pleas?

What I have tried:

C#
 private void button1_Click(object sender, EventArgs e)
        {
                   string exeFolder = Application.StartupPath;
                   string Filepath = Path.Combine(exeFolder, @"Form.pdf");
                    Process printjob = new Process();
                    printjob.StartInfo.FileName = Filepath;
                    printjob.StartInfo.Verb = "Print";
                    printjob.StartInfo.CreateNoWindow = true;
                    printjob.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                    PrinterSettings ps = new PrinterSettings();
                   PrintDocument printdoc= new PrintDocument();
                   printdoc.PrinterSettings = ps;
                   IEnumerable<PaperSize> paperSizes = ps.PaperSizes.Cast<PaperSize>();
                   PaperSize sizeA4 = paperSizes.First<PaperSize>(size => size.Kind == PaperKind.A4);
                    printdoc.DefaultPageSettings.PaperSize = sizeA4;
                    PaperSource oPSource = new PaperSource();
                    oPSource.RawKind = (int)PaperSourceKind.Lower;
                    printdoc.DefaultPageSettings.PaperSource = oPSource;
                    printdoc.PrinterSettings.Copies = 2;            
                    printjob.Start();
}
Posted
Updated 5-Dec-18 6:12am
v2

1 solution

You're using an external process to print a PDF file. That process will use it's own print settings and do the printing itself.

Your PrintDocument code is useless as it only applies to printing inside your own application, when your code does the actual rendering to a PrintDocument page. These classes will not work at all with an external process doing the printing.

You have no control at all over how the external application prints the PDF.
 
Share this answer
 
Comments
loai_maane 6-Dec-18 5:15am    
Thanks a lot Dave ,
I did not get any open source libraries to print the PDF with specific printing settings like Tray number and number of copies .
In my opinion now, I should create function contact with the printers it self and change the settings especially tray number then call that function before print the PDF.what is your suggestions?
My program it is windows Application (C#)
Dave Kreskowiak 6-Dec-18 14:52pm    
If you use an external application to do the printing, you have NO CONTROL AT ALL over it's printing process and settings.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900