changes
This commit is contained in:
32
print/print_barcode.py
Normal file
32
print/print_barcode.py
Normal file
@@ -0,0 +1,32 @@
|
||||
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.")
|
||||
17
print/test_barcode.txt
Normal file
17
print/test_barcode.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
SIZE 50 mm,40 mm
|
||||
GAP 2 mm,0
|
||||
DIRECTION 1
|
||||
DENSITY 8
|
||||
CLS
|
||||
|
||||
TEXT 20,15,"3",0,1,1,"CellphoneS Store"
|
||||
TEXT 20,45,"2",0,1,1,"iPhone 15 Pro Max 256GB"
|
||||
TEXT 20,70,"2",0,1,1,"Color: Natural Titanium"
|
||||
TEXT 20,95,"1",0,1,1,"Price: 29,990,000 VND"
|
||||
TEXT 20,115,"1",0,1,1,"Warranty: 12 months"
|
||||
|
||||
BARCODE 20,140,"128",50,1,0,2,2,"SKU123456789"
|
||||
|
||||
QRCODE 280,140,"L",4,"A",0,"https://example.com/p/123456789"
|
||||
|
||||
PRINT 1,1
|
||||
Reference in New Issue
Block a user