Reputation: 1201
I have been trying to get the status of a print job using win32print in Python.
The status codes provided by win32print don't seem to match the status code for the job in question. I have tried it on different printers but always get the same results.
import win32print
import subprocess
printer_name = win32print.GetDefaultPrinter()
print("Printer: %s" % (printer_name))
hPrinter = win32print.OpenPrinter(printer_name)
try:
hJob = win32print.StartDocPrinter(hPrinter, 1, ("test of raw data", None, "RAW"))
try:
f = open("test2.ps", "r")
win32print.StartPagePrinter(hPrinter)
win32print.WritePrinter(hPrinter, bytes(f.read(), "utf-8"))
win32print.EndPagePrinter(hPrinter)
finally:
win32print.EndDocPrinter(hPrinter)
finally:
print("Printing: %s" % (hJob))
win32print.ClosePrinter(hPrinter)
hPrinter = win32print.OpenPrinter(printer_name)
past_status_code = -0
while True:
try:
job = win32print.GetJob(hPrinter, hJob, win32print.JOB_INFO_1)
except:
break
status_code = job['Status']
if (status_code != past_status_code):
print("Job Status Code: %s" % (status_code))
past_status_code = status_code
if (job['Status'] == win32print.JOB_STATUS_BLOCKED_DEVQ):
print("BLOCKED_DEVQ")
if (job['Status'] == win32print.JOB_STATUS_DELETED):
print("Deleted")
if (job['Status'] == win32print.JOB_STATUS_DELETING):
print("Deleting")
if (job['Status'] == win32print.JOB_STATUS_ERROR):
print("Error")
if (job['Status'] == win32print.JOB_STATUS_OFFLINE):
print("Offline")
if (job['Status'] == win32print.JOB_STATUS_PAPEROUT):
print("PaperOut")
if (job['Status'] == win32print.JOB_STATUS_PAUSED):
print("Paused")
if (job['Status'] == win32print.JOB_STATUS_RESTART):
print("Restart")
if (job['Status'] == win32print.JOB_STATUS_USER_INTERVENTION):
print("User intervention")
if (job['Status'] == win32print.JOB_STATUS_SPOOLING):
print("Spooling")
if (job['Status'] == win32print.JOB_STATUS_PRINTING):
print("Printing")
if (job['Status'] == win32print.JOB_STATUS_PRINTED):
print("Printed")
if (job['Status'] == win32print.JOB_STATUS_COMPLETE):
print("Complete")
After running the script above I always get the same results/ status codes I seem to get 8208 and then a 148.
What I'm tried to do is check when a job has completed.
Upvotes: 4
Views: 3598
Reputation: 965
You can start here:
This script allows you to see your printing job queue. You can customize it using the Get Job documentation if you want to see the information of a specific Job.
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()
Script taken from this post
Upvotes: 1
Reputation: 1
The returned status is a bit mask, as described here , for example . Multiple values can be OR'ed, so your value of 8208(hex 0x00002010) indicates that the printer has (all) status.
Upvotes: 0