0

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)
Zain Khaishagi
  • 135
  • 1
  • 9
  • What does your code look like, how is it not working? [python cups](https://github.com/OpenPrinting/pycups/blob/3a661e382d6ab8404c9d9327bf71e85abe154f42/cupsmodule.c#L911) defines **CUPS_FORMAT_RAW**, so it should be usable. – tink Aug 13 '23 at 20:28
  • @tink, thanks for taking a look. I've added my code now. Let me know if I can provide any more details – Zain Khaishagi Aug 14 '23 at 03:37

0 Answers0