import win32print PRINTER_NAME = "Xprinter XP-350BM" def send(tspl_text): h = win32print.OpenPrinter(PRINTER_NAME) try: win32print.StartDocPrinter(h, 1, ("TSPL REPL", None, "RAW")) win32print.StartPagePrinter(h) win32print.WritePrinter(h, tspl_text.encode('utf-8')) win32print.EndPagePrinter(h) win32print.EndDocPrinter(h) finally: win32print.ClosePrinter(h) print(f"TSPL REPL — sending to: {PRINTER_NAME}") print("Type TSPL commands one per line. Type 'PRINT 1,1' to trigger print.") print("Type 'exit' to quit.\n") buffer = [] while True: line = input("tspl> ").strip() if line.lower() == "exit": break buffer.append(line) # Auto-send whenever a PRINT command is entered if line.upper().startswith("PRINT"): full_command = "\n".join(buffer) + "\n" send(full_command) print(">> Sent to printer.\n") buffer = []