by Prashant
17. June 2009 00:17
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.
[DllImport("Winspool.drv")]
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");
Share or Bookmark this post…
If you enjoyed this post, make sure you subscribe to my RSS feed!
0093286d-4c66-4f7e-ad8a-048e247aaf7f|0|.0
Tags: c#, printing
C#