从Brother QL-800标签打印机打印标签

时间:2019-04-04 16:55:14

标签: python python-3.x windows-10

我正在尝试使用python脚本和brother_ql库从Windows 10打印标签。如何创建和打印标签?

使用PIL,我创建了想要打印在标签上的图像。现在,我想为Brother QL-800标签打印机创建标签。

from brother_ql import BrotherQLRaster, create_label
from brother_ql.backends import backend_factory, guess_backend
from brother_ql.devicedependent import models, label_type_specs, 
label_sizes
from PIL import Image

LABEL_SIZES = [(name, label_type_specs[name]['name']) for name in 
label_sizes]
model = [m for m in models]
printer_model = model[9]  #QL-800
label_type = LABEL_SIZES[12]  #('29x90', '29mm x 90mm die-cut')

im = Image.open('tempQR.png', 'r')
im = im.resize((306, 991))
qlr = BrotherQLRaster(printer_model)

label = create_label(qlr, im, label_size='29x90', threshold=70, cut=True, 
rotate=0)

1 个答案:

答案 0 :(得分:2)

我知道这是一个古老的问题,但是我没有在互联网上的任何地方找到任何文档,所以就在这里。我很开心自己弄清楚了这一点。

从此处阅读“后端”部分:http://brother-ql.net/readme.html,然后下载并运行Windows USB驱动程序过滤器。如果您还没有阅读过,那么值得阅读整个页面。

我已经在Windows 10和运行Raspbian的Raspberry pi 4上测试了此代码。

from PIL import Image
from brother_ql.conversion import convert
from brother_ql.backends.helpers import send
from brother_ql.raster import BrotherQLRaster

im = Image.open('tempQR.png')
im.resize((306, 991)) 

backend = 'pyusb'    # 'pyusb', 'linux_kernal', 'network'
model = 'QL-800' # your printer model.
printer = 'usb://0x04f9:0x209b'    # Get these values from the Windows usb driver filter.  Linux/Raspberry Pi uses '/dev/usb/lp0'.

qlr = BrotherQLRaster(model)
qlr.exception_on_warning = True

instructions = convert(

        qlr=qlr, 
        images=[im],    #  Takes a list of file names or PIL objects.
        label='29x90', 
        rotate='90',    # 'Auto', '0', '90', '270'
        threshold=70.0,    # Black and white threshold in percent.
        dither=False, 
        compress=False, 
        red=False,    # Only True if using Red/Black 62 mm label tape.
        dpi_600=False, 
        lq=False,    # True for low quality.
        no_cut=False

)

send(instructions=instructions, printer_identifier=printer, backend_identifier=backend, blocking=True)

这基本上是brother_ql库文件“ cli.py”中的“ print_cmd”功能