打印打印机作业的Python代码。 我收到错误:
Traceback (most recent call last):
File "C:\Users\Eden\Downloads\102.py", line 29, in <module>
print_job_checker()
File "C:\Users\Eden\Downloads\102.py", line 15, in print_job_checker
phandle = win32print.OpenPrinter(name)
pywintypes.error: (1801, 'OpenPrinter', 'The printer name is invalid.')
代码是:
import time
import win32print
def print_job_checker():
"""
Prints out all jobs in the print queue every 5 seconds
"""
jobs = [1]
while jobs:
jobs = []
for p in win32print.EnumPrinters(win32print.PRINTER_ENUM_LOCAL,
None, 1):
flags, desc, name, comment = p
phandle = win32print.OpenPrinter(name)
print_jobs = win32print.EnumJobs(phandle, 0, -1, 1)
if print_jobs:
jobs.extend(list(print_jobs))
for job in print_jobs:
print "printer name => " + name
document = job["pDocument"]
print "Document name => " + document
win32print.ClosePrinter(phandle)
time.sleep(5)
print "No more jobs!"
if __name__ == "__main__":
print_job_checker()
来源是:http://www.blog.pythonlibrary.org/2013/12/19/pywin32-monitor-print-queue/