def print_thermal(header, title_first, title_seconds, date_time, qr_code, gate_info, type_scan): result = False try: p = Usb(int(CONFIG['PRINTER']['vid'], 0), int(CONFIG['PRINTER']['pid'], 0), int(CONFIG['PRINTER']['timeout'], 0), int(CONFIG['PRINTER']['ep1in'], 0), int(CONFIG['PRINTER']['ep1out'], 0)) p.set("CENTER", "B", "A", 2, 2) p.text(str(header) + "\n\n") p.set("CENTER", "A", "normal", 1, 1) p.text(str(title_first) + "\n") p.text(str(title_seconds) + "\n") p.text(str(date_time) + "\n\n") if (type_scan == 0): p.qr(str(qr_code), 0, 10) else: p.barcode(str(qr_code), "CODE128", function_type="B") p.text("\nPintu Masuk : " + str(gate_info) + "\n*** TERIMAKASIH ***\n\n\n") result = True except Exception as e: print(e) return result
def printStickerLabel(orderNumber): stickerPrinter = Usb(0x1ba0, 0x220a, 0) stickerPrinter.set("center") mydb = mysql.connector.connect(host="62.75.152.102", user="******", passwd="GA2019!?", database="wordpress_b") mydb.autocommit = True # mycursor = mydb.cursor() # mycursor.execute("UPDATE orderPlaced SET collected = IF(made = 1, 1 , 0), made = IF(made = 0, 1 , 1) WHERE orderID = " + str(orderNumber)) mycursor = mydb.cursor() mycursor.execute("SELECT IF(collected = 1, 'Collected' , 'Made') as Output, count(orderLine.extras), IF(orderPlaced.paid,'Paid On App','NEEDS TO PAY'), orderPlaced.orderID, orderPlaced.collection, orderPlaced.amount FROM orderPlaced, orderLine WHERE orderPlaced.orderID = orderLine.orderID AND orderPlaced.orderID = " + str(orderNumber)) myresult = mycursor.fetchall() for x in myresult: for z in range(1,int(x[1]+1)): stickerPrinter.text(" Order Complete \n") stickerPrinter.text(str(x[3]) + "\n\n") stickerPrinter.text(str(x[2]) + "\n\n") stickerPrinter.text(" Collection Time \n") stickerPrinter.text(str(x[4]) + "\n\n") stickerPrinter.text("" + str(z) + " of " + str(int(x[1])) + "\n") stickerPrinter.barcode(str(x[3]), 'CODE39', 64, 2, 'OFF', 'True') if z != x[1]: stickerPrinter.text("\n\n=======================\n\n") else: stickerPrinter.cut() stickerPrinter.close()
def post_add(self, item): stroka = str() len_id = len(str(item.id)) const_len = 9 while(len_id < const_len): stroka += '0' len_id += 1 stroka += str(item.id) p = Usb(0x1d90,0x2060,0,0x81,0x02) p.barcode(stroka,'CODE39',250,3,'','') p.cut() p.barcode(stroka,'CODE39',250,3,'','') p.cut()
class ThermalPrinter(): def __init__(self): self.p = Usb(0x0fe6, 0x811e, 98, 0x82, 0x02) def insert_imagen(self, img_surce): self.p.image(img_surce) def insert_qr(self, content, size): self.p.qr(content, size=size) #size 1 - 16 default 3 def insert_barcode(self, code, bc, height, width): self.p.barcode(code, bc, height=height, width=width) def insert_text(self, txt): self.p.text(txt) def insert_raw_txt(self, txt): self.p._raw(txt) # harware action, may be: INIT, SELECT, RESET def hardware_operation(self, hw): self.p.hw(hw) #string for the following control sequences: # LF for Line Feed # FF for Form Feed # CR for Carriage Return # HT for Horizontal Tab # VT for Vertical Tab #pos = horizontal tab position 1 - 16 def feed_control(self, ctl, pos): self.p.control() self.p.charcode() # #def insert_textln(self, txt): # align = CENTER LEFT RIGHT default left # font_type = A or B default A # textt_type = B(bold), U(underline), U2(underline, version2), BU(for bold and underlined, NORMAL(normal text) defaul tnormal # width = width multiplier decimal 1 - 8 defaul 1 # heigh = height multiplier decimal 1 - 8 defaul 1 # density = density 0 - 8 # def set_txt(self, align, font, text_type, density, height, width): def set_txt(self, *args, **Kwargs): print(Kwargs) self.p.set(Kwargs) def cut_paper(self): self.p.cut()
def printer_print(code): from escpos.printer import Usb p = Usb(int(get_printer_id()[0], 16), int(get_printer_id()[1], 16), 0) if p.paper_status() == 2: text = 'Discount Code:\n\t{}\n'.format(code) p.text(text) p.barcode('1234567898765', 'EAN13', 64, 2, '', '') p.cut() elif p.paper_status() == 1: print('Paper running out soon!') # TODO: inform the manager immediately about the paper issue pass else: # TODO: show warning on screen that the machine is temporarily not able to print out barcode for non-app user, # app users can still scan the barcode on the screen to obtain the voucher code pass
class Printer(): """ Loads a printer according to the model supplied (explicit list of support) and provides common functions """ def __init__(self, name: str = "", model: str = "", **kwargs): if not name: # Forces a unique printer name name = f"printer-{id(self)}" self.name = name if model: self.printer_spec = PRINTER_MAP.get(str(model), dict()) else: self.printer_spec = PRINTER_MAP.get("default") self.model = self.printer_spec.get('model', 'unknown') valid_kwargs = getfullargspec(Usb) # ['self', 'idVendor', 'idProduct', 'timeout', 'in_ep', 'out_ep'] # Look for kwargs passed that match a kwarg for Usb() and override for k, v in kwargs: if k in valid_kwargs: self.printer_spec["config"][k] = kwargs.pop(k, None) self.inputs = locals() config = self.printer_spec['config'] self.printer = Usb(**config) # TODO: Add logic that verifies the printer is working def ln(self, count=1): """ feeds n lines to print buffer replicates Escpos().ln() in newer version (>=3.0) https://github.com/python-escpos/python-escpos/blob/f9ce77705757dcd3a3946569d02810ae7e122e88/src/escpos/escpos.py#L531 """ if count < 0: count = 0 if count == 0: return False return self.printer.text('\n' * count) def text(self, text): """ Pass through to Escpos().text() https://github.com/python-escpos/python-escpos/blob/cbe38648f50dd42e25563bd8603953eaa13cb7f6/src/escpos/escpos.py#L424 """ self.printer.text(text) return True def cut(self, mode="PART"): """ Pass through to Escpos().cut() https://github.com/python-escpos/python-escpos/blob/cbe38648f50dd42e25563bd8603953eaa13cb7f6/src/escpos/escpos.py#L597 """ return self.printer.cut(mode) # TODO: Make this better def barcode(self, *args, **kwargs): """ Pass through to Escpos().barcode() https://github.com/python-escpos/python-escpos/blob/cbe38648f50dd42e25563bd8603953eaa13cb7f6/src/escpos/escpos.py#L295 """ return self.printer.barcode(*args, **kwargs) # TODO: Make this better def qr(self, *args, **kwargs): """ Pass through to Escpos().qr() https://github.com/python-escpos/python-escpos/blob/cbe38648f50dd42e25563bd8603953eaa13cb7f6/src/escpos/escpos.py#L134 """ return self.printer.qr(*args, **kwargs)
from escpos.printer import Usb # Adapt to your needs p = Usb(0x0416, 0x5011, profile="POS-5890") # Print software and then hardware barcode with the same content p.soft_barcode('code39', '123456') p.text('\n') p.text('\n') p.barcode('123456', 'CODE39')
def printSpanish(date, guid, city, state, receiptId, leader, cashier, subtotal, tax, total, payments, eventType, Items, Cashes, Cards): temp = leader.strip().split(' ') leader = "" for x in range(len(temp)): if (len(temp[x]) > 0): leader = leader + " " + temp[x].strip() event = "Seminario : " + city.strip() + ", " + state.strip() leader = "Lider : " + trimHeader( leader.strip() ) cashier = "Cajero : " + cashier.strip() #stuff """ Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """ p = Usb(0x04b8,0x0202,0) p.set("Center") p.image( os.path.dirname(os.path.realpath(__file__)) + "/logo.jpg") p.text(date + "\n") p.barcode( receiptId.strip() , "EAN13") p.text("\n") p.set("left") p.text(event + "\n") p.text(leader + "\n") p.text(cashier + "\n") p.text("\n") p.set("left") # 22 3 4 3 5 # 1234567890123456789011 1234 12345 p.text("Producto Qty Precio\n") # Items[x][0] Items[x][1] + " " + Items[x][2] + "\n") for x in range(len(Items)): #print repr(trimPrice[x][2]) p.text( u''.join( trimName( Items[x][0] ) + trimQty( Items[x][1] ) + trimPrice( Items[x][2] ) + "\n") ) if len(Cards) > 0: p.set("center") p.text("\n") p.text("=====Pagos De Tarjeta=====") p.text("\n\n") p.set('left') for card in Cards: cardStr = "Tipo De Tarjeta : " + card[0] + "\n" cardStr = cardStr + "Numero De Cuenta : " + card[1] + "\n" cardStr = cardStr + "Nombre En La Tarjeta : " + card[2].strip() + "\n" cardStr = cardStr + "Codigo de Autorizacion : " + card[3] + "\n" cardStr = cardStr + "ID de transaccion : " + card[4] + "\n" cardStr = cardStr + "Cantidad : " + trimPrice( str(card[5]) ) + "\n" cardStr = cardStr + "\n" p.text(cardStr) imgData = r''.join( card[7].strip().strip("\n") ) imgData = "%r" % imgData with open("curr_signature.png", "wb") as fh: fh.write(base64.decodestring(imgData)) img = Image.open( os.path.dirname(os.path.realpath(__file__)) + "/curr_signature.png") new_width = 100 new_height = 50 img = img.resize((new_width, new_height), Image.ANTIALIAS) img.save('curr_signature.png') # format may what u want ,*.png,*jpg,*.gif p.set("center") p.image( os.path.dirname(os.path.realpath(__file__)) + "/curr_signature.png" ) p.set("left") if len(Cashes) > 0: p.set('center') p.text("\n") p.text('=====Pagos En Efectivo=====') p.text("\n\n") p.set('left') for cash in Cashes: cashStr = "Efectivo Recibido : " + trimPrice ( str( cash[0]) ) + "\n" cashStr = cashStr + "Cambio : " + trimPrice ( str( cash[1]) ) + "\n" cashStr = cashStr + "\n" p.text(cashStr) p.text("\n\n\n") p.set("right") p.text("Total parcial : " + trimBottomRight( trimPrice( str(subtotal) ) ) + "\n") p.text("Impuestos : " + trimBottomRight( trimPrice( str(tax) ) ) + "\n") p.text("Total : " + trimBottomRight( trimPrice( str(total) ) ) + "\n\n") p.set("Center", "A","B") p.text("Gracias!\n") p.set("Center", "A", "normal") p.text("Customer Copy\n") p.cut()
from escpos.printer import Usb # Adapt to your needs p = Usb(0x0416, 0x5011, profile="POS-5890") # Print software and then hardware barcode with the same content p.soft_barcode("code39", "123456") p.text("\n") p.text("\n") p.barcode("123456", "CODE39")
from escpos.printer import Usb p = Usb(0x0483, 0x5743, 0) p.text("Hello World\n") p.text("Lorem ipsum " * 100) p.qr("http://www.google.it", size=10) p.barcode('1324354657687', 'EAN13', 64, 2, '', '') p.text('\n' * 2) p.cut()
from escpos.printer import Usb # Adapt to your needs p = Usb(0x471, 0x55, 0, 0x82, 0x2) p.text("Hello World\n") # Print image # p.image("logo.gif") # Print QR Code p.qr("You can readme from your smartphone") # Print barcode p.barcode('1324354657687', 'EAN13', 64, 2, '', '') # Cut paper # p.cut() p.text('test') p.text('test') p.barcode('123456', 'CODE39') p.cut() # import usb.core # import usb.util # # # find our device # dev = usb.core.find(0x471, 0x55) # # # was it found? # if dev is None: # raise ValueError('Device not found') # # # set the active configuration. With no arguments, the first # # configuration will be the active one # # dev.set_configuration()
mycursor = mydb.cursor() mycursor.execute( "SELECT IF(collected = 1, 'Collected' , 'Made') as Output, count(orderLine.extras), IF(orderPlaced.paid,'Paid On App','NEEDS TO PAY'), orderPlaced.orderID, orderPlaced.collection, orderPlaced.amount FROM orderPlaced, orderLine WHERE orderPlaced.orderID = orderLine.orderID AND orderPlaced.orderID = " + str(orderNumber)) myresult = mycursor.fetchall() for x in myresult: if (x[0] == "Made"): for z in range(1, int(x[1] + 1)): stickerPrinter.text(" Order Complete \n") stickerPrinter.text((int((2 - len(str(x[3]))) / 2) * " ") + str(x[3]) + "\n\n") stickerPrinter.text((int((6 - len(str(x[2]))) / 2) * " ") + str(x[2]) + "\n\n") stickerPrinter.text(" Collection Time \n") stickerPrinter.text((int((4 - len(str(x[3]))) / 2) * " ") + str(x[4]) + "\n\n") stickerPrinter.text("" + str(z) + " of " + str(int(x[1])) + "\n") #stickerPrinter.barcode("012ABCDabcd", "CODE128", function_type="B") stickerPrinter.barcode('132', 'CODE39', 64, 2, 'OFF', 'True') stickerPrinter.cut() if (z != x[1]): input("Please Tear") else: print("Food Created") elif (x[0] == "Collected"): print("Order Completed") except: print("Not recognised")
font = ImageFont.truetype("/home/francisco/gunplay3.ttf", 50) precio = "$30.00" codigo_barras = '1324354657687' descripcion_producto = '123456789 123456789 123456789 123456789' #Calcular el ancho y alto del font imgFont = Image.new("RGBA", (400, 200), (255, 255, 255)) drawFont = ImageDraw.Draw(imgFont) WF, HF = drawFont.textsize(precio, font=font) deltaHF = int(round((HF * 0.40))) #Calcular el tamano del lienzo para dibujar W, H = (WF + 4, HF + deltaHF) img = Image.new("RGBA", (W, H), (255, 255, 255)) draw = ImageDraw.Draw(img) #Dibujar el precio draw.text(((W - WF) / 2, 1), precio, (0, 0, 0), font=font) #Dibujar un recuadro dentro de la imagen. #draw.rectangle(((0, 0), (W-1, H-1)),outline="red") img.save("a_test.png") p.text(descripcion_producto + "\n") p.barcode(codigo_barras, 'EAN13', 64, 2, '', '') p.image("a_test.png") p.barcode(codigo_barras, 'EAN13', 34, 2, '', '') #p.cut(mode='FULL',feed=False) #El origininal tenia. self._raw(b"\n\n\n\n\n\n") #Cortar el papel y corregir fix con saltos de linea. p._raw(b"\n\n\n\n\n") p._raw(PAPER_FULL_CUT)