Using printer name to get details in python

49 Views Asked by At

this code is working but its not cutting the paper after printing,

printer_name = "EPSON T20iii"
raw_data = bytes(receipt_text, "utf-8")

drivers = win32print.EnumPrinterDrivers(None, None, 2)
hPrinter = win32print.OpenPrinter(printer_name)
printer_info = win32print.GetPrinter(hPrinter, 2)
for driver in drivers:
    if driver["Name"] == printer_info["pDriverName"]:
        printer_driver = driver

raw_type = "XPS_PASS" if printer_driver["Version"] == 4 else "RAW"

try:
    hJob = win32print.StartDocPrinter(hPrinter, 1, ("test of raw data", None, raw_type))
    try:
        win32print.StartPagePrinter(hPrinter)
        win32print.WritePrinter(hPrinter, raw_data)
        win32print.WritePrinter(hPrinter, b'\x1b\x4A')
        win32print.EndPagePrinter(hPrinter)
    except Exception as e:
        message.warning(request, f"Error! {e}")
    finally:
        win32print.EndDocPrinter(hPrinter)
        
except Exception as e:
    message.warning(request, f'Error! {e}')
finally:
    win32print.ClosePrinter(hPrinter)

message.success(request, 'Test printer job send') 

I have asked for some [help][1] here but didn't get any. So i have decided to use this code instead, since its clearly giving a cut() command:

from escpos.printer import Usb

""" Seiko Epson Corp. Receipt Printer (EPSON TM-T88III) """
p = Usb(0x04b8, 0x0202, 0, profile="TM-T88III")
p.text("Hello World\n")
p.image("logo.gif")
p.barcode('4006381333931', 'EAN13', 64, 2, '', '')
p.cut()

However there is another problem, getting product and vendor ids is has proven to be more challenging than expected. Using Windows interface, in some systems it dose not show, in some it shows two different ids, so i have decided to use the win32print to create a printer object since i can simply create it by printer name, then extract the ids from there. Yah, it didn't work. I'm looking for any method that can help in this situation. Its been day since i got stuck on this. Thank you in advance. [1]: Cut paper in win32print POS

0

There are 0 best solutions below