我像这段代码一样使用python3和win32print。它应该删除所有打印作业,因为TotalPages> = 1。我认为所有数据类型都是正确的。
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(job['TotalPages'])
if(job['TotalPages'] >= 1):
print(type(job))
win32print.SetJob(phandle, job['JobId'], 1, job, win32print.JOB_CONTROL_DELETE)
win32print.ClosePrinter(phandle)
time.sleep(0.25)
print ("No more jobs!")
#----------------------------------------------------------------------
if __name__ == "__main__":
while True:
print_job_checker()
当我运行它时会显示错误。
文件" C:/Users/test_printer.py",第37行,在print_job_checker中 win32print.SetJob(phandle,job [' JobId'],1,job,win32print.JOB_CONTROL_DELETE)
错误:(1804,' SetJob','指定的数据类型无效。')
答案 0 :(得分:0)
由于您正在删除而不是更改作业属性,请尝试此操作;
win32print.SetJob(phandle, job['JobId'], 0, None, win32print.JOB_CONTROL_DELETE)
以下参数已更改:
等级= 0
pPrinter =无