Via trial and error and looking into the ppd I wrote script below that allows you to print on different trays. I found the correct names for value and key of the job-options in the ppd.
Just by looking into conn.getPrinterAttributes(printer)['media-source-supported'] those options do not became clear.
I feel like there must be a way how you can get all the possible job options in a better fashion than just looking them up in the ppd file, but I fail to find any documentation on this problem and because the underlying base is in C, I am also a bit unsure how the connection between python and C works there.
In order to better understand how to use pycups and maybe also how the connection between python and C works here, I decided to ask on stackoverflow.
I have ...
Following pycups
Followed pip show pycups but only found the cupshelpers and pycups info i.e.
This is a set of Python bindings for the libcups library from CUPS project.
But I didn't find the exact bindings only:
cups.cpython-310-x86_64-linux-gnu.so
cupsext.cpython-310-x86_64-linux-gnu.so
cupshelpers/
cupshelpers-1.0-py3.10.egg-info
pycups-2.0.1.egg-info
Program for reference
#!/usr/bin/env python3
import cups
def list_printers():
conn = cups.Connection()
printers = conn.getPrinters()
print("Available printers:")
for printer in printers:
print(f"Printer: {printer}")
print("Supported options:")
options = conn.getPrinterAttributes(printer)['media-source-supported']
for option in options:
cleaned_option = ''.join(c for c in option if c.isalnum()).upper()
print(f" {cleaned_option}")
print()
def print_document(printer_name, document_path, tray_option):
conn = cups.Connection()
printers = conn.getPrinters()
if printer_name not in printers:
print(f"Printer '{printer_name}' not found.")
return
job_options = {
'InputSlot': tray_option,
}
print(job_options)
with open(document_path, 'rb') as document:
print_job_id = conn.printFile(printer_name, document_path, "Print Job", job_options)
print(f"Document '{document_path}' sent to '{printer_name}' with Job ID: {print_job_id}")
if __name__ == "__main__":
# Specify the printer name, document paths, and tray options
printer_name = "Kyocera-ECOSYS-P3055dn-KPDL"
document1_path = "Tray1.pdf"
document2_path = "Tray2.pdf"
options = ["PF430A", "PF430B"]
for option in options:
print_document(printer_name, f"{option}.pdf", option)