在发送作业之前检查打印机缺纸

时间:2013-01-22 12:15:06

标签: c# printing status

我正在尝试获取打印机的信息。使用WMI我可以检索一些信息,但仅限于已发送作业。

我需要在发送作业之前检查我的打印机是否缺纸。

这可能吗?

3 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

检查DetectedErrorState属性,3为低纸,4为无纸,5为低碳粉

答案 2 :(得分:0)

这就是我的方法...

   //check PAPER OK and Toner OK
    private static bool IspaperOK(ManagementBaseObject printer)
    {
        bool PaperOK = true;

        string[] printers = ConfigurationManager.AppSettings["ModelliStampanti"].Trim().Split('#');

        foreach (var property in printer.Properties)
        {

            if (property.Name == "DeviceID")
            {
                var PaperStatus = printer.Properties["PrinterState"].Value.ToString();
                for (int i = 0; i <= printers.Length - 1; i++)
                {

                    if (property.Value.ToString() == printers[i].ToString())
                    {     //131072 = Toner Low
                          //1024 = printing
                          //16 = Out of Paper
                          //5 = out of paper
                          //128 - offline(no internet connection)   


                          //this is for out of paper....
                        if ((PaperStatus == "5") ||(PaperStatus == "16"))
                        {
                            PaperOK = false;
                        }

                        //this is for low toner....
                        if (PaperStatus == "131072")
                        {
                            PaperOK = false;
                        }

                    }

                }


            }

        }
        return PaperOK;
    }

要验证这些问题,请使用这些值而不是MSDN中描述的值

                //131072 = Toner Low
                //1024 = printing
                //16 = Out of Paper
                //5 = out of paper
                //128 - offline(no internet connection OR printer turned off )