Linux系統下很少有對打印機做驅動支持,自己做起來又有非常麻煩,還好大多數打印機都能夠支持escpos協議,因此我們可以做到無驅動打印。
1、安裝python-usb庫
git clone https://github.com/walac/pyusb.git
cd pyusb
sudo python setup.py install
2、安裝python-escpos庫
sudo pip install python-escpos==1.0.9
3、安裝python qrcode模塊
pip install qrcode==5.1
4、插上usb打印機並通電,使用命令查看是否識別到設備
ls -l /dev/usb
如果識別到則會顯示:/dev/usb/lp0
5、編寫python代碼
# -*- coding: UTF-8 -*- from escpos import * p = printer.File("/dev/usb/lp0") p.text("Hello World\n") p.text("CRCRCR12345678910\n") p.text("CRCRCR12345678910\n") p.text("CRCRCR12345678910\n") p.text("CRCRCR12345678910\n") p.qr("123456789") p.qr("123456789") p.set(codepage=None, align='center') p.cut() p.close()
6、運行代碼實現打印
