Skip to content

printFile do not work #52

Description

@XiaofanFTD

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions