Set the default printer for printing programatically

16. June 2009 15:17

C# Code Snippets  0 Comments

You need to print the document but you don't want to go to control panel or printer and faxes options and just want to get it changed automatically. You can even set the shared local network printer with this code.

Just with the code you can override the system settings and change the default printer for your system.

You need to use the namespace so in order to use the DLLImport attribute.

using System.Runtime.Interopservices;
//Set default printer to the one available with your system or network.
private static extern bool SetDefaultPrinter(string printerName);

Now on button click or on form load just change the printer you want to use while printing and then change it back to the one before.

//Set the default printer. I have set it as my Adobe PDF printer
SetDefaultPrinter("Adobe PDF");
Currently rated 5.0 by 1 person

Comments (0)

Add Comment

Visit to discover Indian blogs Computers Blogs