label_printer/flask/print.py
2024-09-14 20:49:57 +02:00

23 lines
416 B
Python

dev_path="/dev/usb/lp0"
def print_text(stream, text):
stream.write(text.encode('utf-8'))
def cut_paper(stream):
stream.write(b'\x1DVA\xc8')
def print_image(image):
buffer = io.BytesIO()
image.save(buffer, format='PBM')
pbm_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
stream = open('/dev/usb/lp0', 'wb')
print_text(stream, "test\n")
cut_paper(stream)
stream.close()