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 printTicketFunc(expirationDate, name, email, type, description, printTime): p = Usb(0x04b8, 0x0e15, 0) p.set(align='center', text_type='B', width=4, height=4) p.text(expirationDate) p.text("\n") p.set(align='center', width=1, height=1) p.text("storage expiration date\n\n") p.set(align='center', width=2, height=2) p.text("DMS Storage Ticket\n\n") p.set(align='left') p.text("Ticket required on any items left at DMS.\n") p.text("Place ticket in holder or on project.\n\n") p.set(align='left') p.text(str.format("Name:\t{}\n", name)) p.text(str.format("Email:\t{}\n", email)) p.text(str.format("Type:\t{}\n", type)) p.text(str.format("Desc:\t{}\n", description)) p.text(str.format("Start:\t{}\n", printTime)) p.text("\n\n") p.text("Signature: ____________________________________\n") p.text( "By signing you agree to follow the posted rules and remove your item before the expiration date.\n" ) p.text( "Failure to remove items will result in loss of\nstorage privileges.") p.set(align='center') p.text("\n") qrDataString = str.format("{};{};{};{}", name, email, type, printTime) p.qr(qrDataString, 1, 6, 2) p.cut() p.set(align='center', width=2, height=2) p.text("DMS Storage Receipt\n\n") p.set(align='left', width=1, height=1) p.text("Keep this receipt as a reminder that you\n") p.text("agreed to remove your item before:\n") p.set(align='center', text_type='B', width=2, height=2) p.text(expirationDate) p.text("\n\n") p.set(align='left') p.text(str.format("Name:\t{}\n", name)) p.text(str.format("Email:\t{}\n", email)) p.text(str.format("Type:\t{}\n", type)) p.text(str.format("Desc:\t{}\n", description)) p.text(str.format("Start:\t{}\n", printTime)) 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()
class Print(object): def __init__(self): self.p = Usb(0x28e9, 0x0289, 0, out_ep=0x03) def __str__(self): return __repr__ = __str__ def cut(self): self.p.cut() def setText(self, size): self.p.set(align = u'center', font = u'a', smooth = True, width = size, height = size) def putImage(self, imagePath): self.p.image(str(imagePath)) def putQr(self, qrInfo, qrSize = 10): self.p.qr(qrInfo, size = qrSize) def putBarcode(self, barcodeInfo): self.barcode(barcodeInfo, 'EAN13', 64, 2, '', '') def putText(self, text, textSize = 1): self.setText(textSize) self.p.text(text) def printResult(self, weight, volume, density): self.putText("******************************\n") self.putText(time.asctime()) self.putText("\n") self.putText("\n") self.putText("Measured results are as follows:\n") self.putText("\n") self.putText("Weight: ") self.putText(str(weight)) self.putText("\n") self.putText("Volume: ") self.putText(str(volume)) self.putText("\n") self.putText("Density: ") self.putText(str(density)) self.putText("\n") self.putText("\n") self.putText("Scan qr to check the result!\n") self.putQr("Weight: {weight}\nVolume: {volume}\nDensity: {density}".format(weight = weight, volume = volume, density = density)) self.cut()
def print_bar(name): width = 580 height = 100 image = Image.new('1', (width, height), 255) draw = ImageDraw.Draw(image) #font1 = ImageFont.truetype('clamp-1m-w4-regular.ttf', 50, encoding='unic') #draw.text((0, 0), "Barcode" + " ", font=font1, fill=0) font2 = ImageFont.truetype('Code39Barcode.ttf', 55) draw.text((0, 00), "*" + name + "*" + " ", font=font2, fill=0) p = Usb(0x0416, 0x5011, 0, 0x81, 0x03) p.text(" " + name + "\n") p.image(image) p.qr(name, size=6) #p.barcode("1324354", "CODE39") #p.barcode("{B012ABCDabcd", "CODE39", function_type="B") p.cut() return ''
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)
import sys from escpos.printer import Usb def usage(): print("usage: qr_code.py <content>") if __name__ == '__main__': if len(sys.argv) != 2: usage() sys.exit(1) content = sys.argv[1] # Adapt to your needs p = Usb(0x0416, 0x5011, profile="POS-5890") p.qr(content)
from escpos.printer import Usb from escpos import * from time import sleep # Adapt to your needs p = Usb(0x0471, 0x0055, timeout=0, in_ep=0x82, out_ep=0x02) #~ p = escpos.Escpos(0x0471, 0x0055,0) # Print software and then hardware barcode with the same content # p.soft_barcode('code39', '123456') for idx in range(1): p.set(align='center', font='b', width=2, height=2) p.text('Ricevuta numero {}\n'.format(idx + 1)) p.text('\n') p.set(align='left', font='c', width=3, height=3) p.text('Hello world\n') p.image('logo_bn.png') p.text('\n') p.set(align='right', font='a', width=1, height=1) p.text('Boxoffice LTC\n') p.text('\n') p.barcode('123456', 'CODE39') #~ p.print_and_feed(n=2) p.text('\n') p.qr("Prenotazione 00056", ) p.text('\n') sleep(1) p.cut(mode=u'FULL')
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()
#coding: utf-8 #test from escpos.printer import Usb """ Seiko Epson Corp. Receipt Printer (EPSON TM-T88III) """ p = Usb(0x28e9, 0x0289, 0, out_ep=0x03) p.set(align=u'center', font=u'a', smooth=True, width=1, height=1) p.text("\u90edHello World\n") #p.image("victors.png") #p.block_text('guo jian wei and tang jia hui', font='a') p.qr('Victors', size=10) p.barcode('1324354657687', 'EAN13', 64, 2, '', '') p.cut()
import sys from escpos.printer import Usb def usage(): print("usage: qr_code.py <content>") if __name__ == '__main__': if len(sys.argv) != 2: usage() sys.exit(1) content = sys.argv[1] # Adapt to your needs p = Usb(0x0416, 0x5011, profile="POS-5890") p.qr(content, center=True)
# -*- coding: utf-8 -*- from escpos.printer import Usb """ Define Thermal USB View info : sudo lsusb -vvv -d 0483:5840 """ ID_VENDOR = 0x0483 ID_PRODUCT = 0x5840 TIMEOUT = 0 EP_1_IN = 0x81 EP_1_OUT = 0x03 p = Usb(ID_VENDOR, ID_PRODUCT, TIMEOUT, EP_1_IN, EP_1_OUT) p.set("CENTER", "B", "A", 2, 2) p.text("KARCIS PARKIR\n\n") p.set("CENTER", "A", "normal", 1, 1) p.text("MALL EPICENTRUM\n") p.text("Gedung Epicentrum Kuningan\n") p.text("Tanggal : 11/20/2019 12:39\n\n") #p.barcode("123456789", "CODE128", function_type="B") p.qr("S4353453", 0, 10) p.text("\nPintu Masuk : Gate 1\n*** TERIMAKASIH ***\n\n\n")