How to check if printer is ready using c#

Say we have a document and we need to print it directly from our program instead of asking for help from PrintDialog or some other built-in feature. Before we send command to the printer, to print, we do need to check that printer is ready for command execution and there is no problem with it. Other wise, printer may raise error for any reason like, out of paper or ink problems or any thing else. This will cause an exception to be raised which is going to make the customer think .$5^&*…. about us which is not desirable.

So, is there any way to check if the device is ready ? before we send the print command ?

Here are two of the several methods, we can use to do so


        public bool CheckMyPrinter(string printerToCheck)
          ManagementObjectSearcher searcher = new  
              ManagementObjectSearcher("SELECT * FROM   Win32_Printer"); 

          bool IsReady = false;
          foreach (ManagementObject printer in searcher.Get())
            if (printer["Name"].ToString().ToLower().Equals(printerToCheck))
              if (printer["WorkOffline"].ToString().ToLower().Equals("false"))
                  IsReady = true;
          return IsReady ;

METHOD 2: Will throw Exception, but you can catch it and work accordingly

            bool printerStatus = false;
                PrintDocument pd = new PrintDocument                                            
                                PrinterSettings = new  PrinterSettings 
                                       PrinterName = "Name"
                printerStatus = pd.PrinterSettings.IsValid;
            catch (System.Exception ex)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s