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.