forked from Distrotech/pycups
-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
link = 'http://example.pdf'
conn = cups.Connection()
printers = conn.getPrinters()
printer_name = list(printers.keys())[0]
print(printers)
print(printer_name)
print(link)
resp = requests.get(link)
content = resp.content
temp = tempfile.NamedTemporaryFile(delete=False, suffix='.pdf')
try:
temp.write(content)
temp.seek(0)
job_attrs = {
'print-color-mode': 'monochrome',
'copies': '2',
'document-format': cups.CUPS_FORMAT_AUTO,
# 'document-format': 'application/pdf',
}
print(temp.name)
job_id = conn.printFile(printer_name, temp.name, 'label11111', job_attrs)
while True:
job_status = conn.getJobAttributes(job_id)
job_state = job_status.get('job-state')
if job_state is None:
print(f"Job {job_id} not found in the queue.")
break
elif job_state == 9:
print(f"Job {job_id} status: completed")
break
else:
print(f"Job {job_id} status: {job_state}")
time.sleep(1)
temp.close()
except Exception as e:
print(f"An error occurred: {e}")
finally:
temp.close()
out:
Job 198 status: 5
Job 198 status: 5
Job 198 status: 5
Job 198 status: completed
but no printed
Metadata
Metadata
Assignees
Labels
No labels