32 lines
808 B
Python
32 lines
808 B
Python
import win32print
|
|
import sys
|
|
import json
|
|
|
|
def print_barcode(tspl_content, printer_name="Xprinter XP-350BM"):
|
|
h = win32print.OpenPrinter(printer_name)
|
|
try:
|
|
win32print.StartDocPrinter(h, 1, ("Print Barcode", None, "RAW"))
|
|
win32print.StartPagePrinter(h)
|
|
win32print.WritePrinter(h, tspl_content.encode('utf-8'))
|
|
win32print.EndPagePrinter(h)
|
|
win32print.EndDocPrinter(h)
|
|
finally:
|
|
win32print.ClosePrinter(h)
|
|
|
|
if __name__ == "__main__":
|
|
data = json.loads(sys.argv[1])
|
|
|
|
tspl = f'''
|
|
SIZE 50 mm,40 mm
|
|
GAP 2 mm,0
|
|
DIRECTION 1
|
|
DENSITY 8
|
|
CLS
|
|
TEXT 20,15,"3",0,1,1,"{data['name']}"
|
|
TEXT 20,70,"1",0,1,1,"Price: {data['price']} VND"
|
|
BARCODE 20,140,"128",50,1,0,2,2,"{data['imei']}"
|
|
PRINT 1,1
|
|
'''.strip()
|
|
|
|
print_barcode(tspl)
|
|
print("Sent to printer.") |