When using lp
I can send -o raw
as option to print raw file. But how do i do this using pycups ?
I've been trying to find the answer to this since yesterday through the sparse documentation but haven't found anything.
import cups
import subprocess
def print_pwg_raster(file_path, printer_name, page_range=None):
conn = cups.Connection()
printer_info = conn.getPrinters()
if printer_name in printer_info:
options = ["-m", "image/pwg-raster"]
if page_range:
options.extend(["-o", f"page-ranges={page_range}"])
# Convert the file to PWG Raster using cupsfilter
pwg_raster_data = subprocess.check_output(["cupsfilter"] + options + [file_path])
# Get the printer URI
printer_uri = printer_info[printer_name]["device-uri"]
# Send the PWG Raster data as raw print data
print_job = conn.printFile(printer_name, file_path, "Print Job" , options= {???} #options
)
print("Print job ID:", print_job)
else:
print("Printer not found:", printer_name)
file_path = "/home/.../w1.pdf" # Replace with the actual file path
printer_name = "Canon_G5000_series" # Replace with the desired printer name
page_range = "1-2" # Replace with the desired page range, e.g., "1-3" for pages 1 to 3
print_pwg_raster(file_path, printer_name, page_range)