[.net] Cutomizing print settings in C#

Started by
0 comments, last by TheTroll 15 years, 11 months ago
Hello everyone. I am designing a program that will (hopefully) allow users to customize and store printer settings and allow them to print out different types of documents using the settings they specified. I know it's fairly straight forward to use a Process to launch the file's associated application and send a print command, like:
Process proc = new Process();
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.Verb = “print”;
proc.StartInfo.FileName = “C:\\foo.txt”;
proc.Start();
proc.WaitForExit(10000);
proc.CloseMainWindow();
proc.Close();
But, how can I specify what printer settings I want to use with this method? I can't see a way to tell the application, "Hey, I want to use duplex printing and only print the first page of this document." Is there any way to provide your own printer settings before the document is sent to the print spooler? Perhaps yank the documents off the print queue before they start and re-send them with my custom settings? I don't know how viable that would be, though. Another problem is I want this to work with multiple file types (such as .doc and .xls). I know that COM is an option, but I'd be out of luck with proprietary formats such as pdf etc. With all that said, I'd appreciate any help or suggestions. =)
Advertisement
The namespace you looking for is System.Drawing.Printing.

In there there are PageSettings, PrintDocument and PageSettings. Those will pretty much do everything you need to do.

Some examples;

            System.Drawing.Printing.PageSettings pageSettings;            System.Drawing.Printing.PrinterSettings printerSettings;            if (printerSettings.CanDuplex == true)                printerSettings.Duplex = true;            pageSettings.Landscape = true;            pageSettings.Margins = new System.Drawing.Printing.Margins(50, 50, 50, 50);  //Margins to a half on inch.


Hope that helps.
theTroll

This topic is closed to new replies.

Advertisement