使用brother_ql打印贴纸时QL-820NWB上下边距冗余问题求助
解决Brother QL-820NWB打印时上下多余边距的问题
问题核心在于:你调用convert函数后再修改qlr参数的操作完全无效——convert会根据指定的62red标签规格自动添加默认的35单位feed_margin,打印指令在convert执行时就已经生成,后续修改qlr不会改变已生成的指令。以下是两种可行的解决方法:
方案一:临时修改标签默认边距
直接修改62red标签的feed_margin值为0,让convert自动使用0边距:
from brother_ql.conversion import convert from brother_ql.backends.helpers import send from brother_ql.raster import BrotherQLRaster from brother_ql.labels import label_specs import os def print_label_from_png(png_in, delete_after_print=True): printerdata_model = 'QL-820NWB' qlr = BrotherQLRaster(printerdata_model) qlr.exception_on_warning = True qlr.mlength = 0 # 让打印机自动适配内容长度 # 临时将62red标签的feed_margin设为0(全局生效,若其他地方用该标签会受影响) label_specs['62red']['feed_margin'] = 0 instructions = convert( qlr=qlr, images=[png_in], label='62red', rotate='auto', threshold=70.0, dither=False, compress=False, red=True, dpi_600=False, hq=True, cut=True ) it_worked = send_data_to_printer(instructions) if delete_after_print: os.remove(png_in) return it_worked
方案二:手动控制边距,阻止convert自动添加
如果不想全局修改标签规格,可以手动添加0边距并标记已完成设置,让convert不再重复添加默认边距:
from brother_ql.conversion import convert from brother_ql.backends.helpers import send from brother_ql.raster import BrotherQLRaster import os def print_label_from_png(png_in, delete_after_print=True): printerdata_model = 'QL-820NWB' qlr = BrotherQLRaster(printerdata_model) qlr.exception_on_warning = True qlr.mlength = 0 # 自动适配内容长度 # 手动添加0边距,并标记已完成,避免convert重复添加默认边距 qlr.add_margins(0) qlr.ends_with_margin = True instructions = convert( qlr=qlr, images=[png_in], label='62red', rotate='auto', threshold=70.0, dither=False, compress=False, red=True, dpi_600=False, hq=True, cut=True ) it_worked = send_data_to_printer(instructions) if delete_after_print: os.remove(png_in) return it_worked
额外检查项
- 确认你的PNG文件本身没有上下多余空白,图像高度是你需要的实际打印长度
- 方案一的修改是全局的,若脚本其他地方也用到
62red标签,会同步使用0边距
内容的提问来源于stack exchange,提问作者Kane
相关产品推荐
相关产品推荐

