哪位大神知道C#中如何获取打印机的打印结果。不是当前打印机状态。十万火急,万分感谢
C#如何能获取到打印机一个打印任务完成后的打印结果的状态。就是打印成功还是失败的状态。打印机API中有支持的方法么? --------------------编程问答-------------------- 对Windows打印系统(spooler)来说,把打印任务发给打印机就算打印完成了,Spooler API只能查到这里。
对打印机来说,打印机具体打印的时候,可能还会出现缺纸,卡纸,缺墨等问题。
某些打印机(包括驱动程序)支持双向通讯,这种情况下spooler可能汇报更具体的打印状态。
打印机的状态查询和任务查询,没有统一的接口。有些打印机支持PJL查询,有些支持SNMP查询,有些使用内部协议。
--------------------编程问答-------------------- 参考:
Is there a way to check if a printing process was successful?
http://stackoverflow.com/questions/11769351/is-there-a-way-to-check-if-a-printing-process-was-successful --------------------编程问答--------------------
--------------------编程问答--------------------
public static string GetPrinterStatus(string PrinterName)
{
int intValue = GetPrinterStatusInt(PrinterName);
string strRet = string.Empty;
switch (intValue)
{
case 0:
strRet = "准备就绪(Ready)";
break;
case 0x00000200:
strRet = "忙(Busy)";
break;
case 0x00400000:
strRet = "被打开(Printer Door Open)";
break;
case 0x00000002:
strRet = "错误(Printer Error)";
break;
case 0x0008000:
strRet = "初始化(Initializing)";
break;
case 0x00000100:
strRet = "正在输入,输出(I/O Active)";
break;
case 0x00000020:
strRet = "手工送纸(Manual Feed)";
break;
case 0x00040000:
strRet = "无墨粉(No Toner)";
break;
case 0x00001000:
strRet = "不可用(Not Available)";
break;
case 0x00000080:
strRet = "脱机(Off Line)";
break;
case 0x00200000:
strRet = "内存溢出(Out of Memory)";
break;
case 0x00000800:
strRet = "输出口已满(Output Bin Full)";
break;
case 0x00080000:
strRet = "当前页无法打印(Page Punt)";
break;
case 0x00000008:
strRet = "塞纸(Paper Jam)";
break;
case 0x00000010:
strRet = "打印纸用完(Paper Out)";
break;
case 0x00000040:
strRet = "纸张问题(Page Problem)";
break;
case 0x00000001:
strRet = "暂停(Paused)";
break;
case 0x00000004:
strRet = "正在删除(Pending Deletion)";
break;
case 0x00000400:
strRet = "正在打印(Printing)";
break;
case 0x00004000:
strRet = "正在处理(Processing)";
break;
case 0x00020000:
strRet = "墨粉不足(Toner Low)";
break;
case 0x00100000:
strRet = "需要用户干预(User Intervention)";
break;
case 0x20000000:
strRet = "等待(Waiting)";
break;
case 0x00010000:
strRet = "热机中(Warming Up)";
break;
default:
strRet = "未知状态(Unknown Status)";
break;
}
return strRet;
}
internal static int GetPrinterStatusInt(string PrinterName)
{
int intRet = 0;
IntPtr hPrinter;
structPrinterDefaults defaults = new structPrinterDefaults();
if (OpenPrinter(PrinterName, out hPrinter, ref defaults))
{
int cbNeeded = 0;
bool bolRet = GetPrinter(hPrinter, 2, IntPtr.Zero, 0, out cbNeeded);
if (cbNeeded > 0)
{
IntPtr pAddr = Marshal.AllocHGlobal((int)cbNeeded);
bolRet = GetPrinter(hPrinter, 2, pAddr, cbNeeded, out cbNeeded);
if (bolRet)
{
PRINTER_INFO_2 Info2 = new PRINTER_INFO_2();
Info2 = (PRINTER_INFO_2)Marshal.PtrToStructure(pAddr, typeof(PRINTER_INFO_2));
intRet = System.Convert.ToInt32(Info2.Status);
}
Marshal.FreeHGlobal(pAddr);
}
ClosePrinter(hPrinter);
}
return intRet;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal struct structPrinterDefaults
{
[MarshalAs(UnmanagedType.LPTStr)]
public String pDatatype;
public IntPtr pDevMode;
[MarshalAs(UnmanagedType.I4)]
public int DesiredAccess;
};
状态枚举
[FlagsAttribute]
internal enum PrinterStatus
{
PRINTER_STATUS_BUSY = 0x00000200,
PRINTER_STATUS_DOOR_OPEN = 0x00400000,
PRINTER_STATUS_ERROR = 0x00000002,
PRINTER_STATUS_INITIALIZING = 0x00008000,
PRINTER_STATUS_IO_ACTIVE = 0x00000100,
PRINTER_STATUS_MANUAL_FEED = 0x00000020,
PRINTER_STATUS_NO_TONER = 0x00040000,
PRINTER_STATUS_NOT_AVAILABLE = 0x00001000,
PRINTER_STATUS_OFFLINE = 0x00000080,
PRINTER_STATUS_OUT_OF_MEMORY = 0x00200000,
PRINTER_STATUS_OUTPUT_BIN_FULL = 0x00000800,
PRINTER_STATUS_PAGE_PUNT = 0x00080000,
PRINTER_STATUS_PAPER_JAM = 0x00000008,
PRINTER_STATUS_PAPER_OUT = 0x00000010,
PRINTER_STATUS_PAPER_PROBLEM = 0x00000040,
PRINTER_STATUS_PAUSED = 0x00000001,
PRINTER_STATUS_PENDING_DELETION = 0x00000004,
PRINTER_STATUS_PRINTING = 0x00000400,
PRINTER_STATUS_PROCESSING = 0x00004000,
PRINTER_STATUS_TONER_LOW = 0x00020000,
PRINTER_STATUS_USER_INTERVENTION = 0x00100000,
PRINTER_STATUS_WAITING = 0x20000000,
PRINTER_STATUS_WARMING_UP = 0x00010000
}
版主威武啊
--------------------编程问答-------------------- 想要获取的是在打印过程完毕之后打印队列里面已经打印完毕的某条信息的成功状态。
补充:.NET技术 , C#