python - 尝试使用 ZPL 到斑马打印机进行打印

标签 python printing zebra-printers zpl

所以我尝试使用 ZPL 语言打印到斑马打印机,但是当我运行下面的代码时,我得到的只是空白标签,知道为什么它不读取 ZPL 变量“标签”。我已将代码放入标签中,它看起来是正确的,但我无法让它打印 ZPL,它只是空白标签。

    import os
from PIL import Image
import zpl
from zebra import Zebra

lines = []
with open(
        r'C:\Users\matthew.vandruff\Downloads\Hard Drives (version '
        r'1)-b0dd6970-7dfd-4bb7-b04d-fc9c3ff4bc8a-a54c9c76-f7e2-40b1-8ff4-6d7eec1c99bb.csv') as f:
    for line in f.readlines():
        l, name = line.strip().split(',')
        lines.append((l, name))

list = lines
x = 1
while x < len(list):
    HD_Serial, HD_Number = list[x]
    # print(HD_Serial, HD_Number)
    x += 1

l = zpl.Label(100, 60)
height = 0
height += 5
l.origin(30, height)
l.write_barcode(height=70, barcode_type='C', check_digit='Y')
l.write_text(f'{HD_Number}')
l.endorigin()

height += 0
image_width = 12
l.origin((l.width - image_width) / 3, height)
image_height = l.write_graphic(
    Image.open(os.path.join(os.path.dirname(zpl.__file__), 'MTC_Logo.png')),
    image_width)
l.endorigin()

height += image_height + 5
l.origin(15, height)
l.write_barcode(height=70, barcode_type='C', check_digit='Y')
l.write_text(f'{HD_Serial}')
l.endorigin()

print(l.dumpZPL())

z = Zebra()
Q = z.getqueues()
z.setqueue(Q[0])
z.setup()
z.autosense()
z.output(l)

最佳答案

所以我猜我的问题出在打印机的设置上,但这是我的最终工作代码,供任何前来查看的人使用,并且在尝试打印时只会出现空白。

import os
from PIL import Image
import zpl
from zebra import Zebra

lines = []
with open(
        r'C:\Users\matthew.vandruff\Downloads\Hard Drives (version '
        r'1)-b0dd6970-7dfd-4bb7-b04d-fc9c3ff4bc8a-a54c9c76-f7e2-40b1-8ff4-6d7eec1c99bb.csv') as f:
    for line in f.readlines():
        l, name = line.strip().split(',')
        lines.append((l, name))

list = lines
x = 1
while x < len(list):
    HD_Serial, HD_Number = list[x]
    # print(HD_Serial, HD_Number)
    x += 1



l = zpl.Label(100, 100)
height = 0
height += 15
l.origin(23, height)
l.write_barcode(height=80, barcode_type='C', check_digit='Y')
l.write_text(f'{HD_Number}')
l.endorigin()

height += 0
image_width = 12
l.origin((l.width - image_width) / 10, height)
image_height = l.write_graphic(
    Image.open(os.path.join(os.path.dirname(zpl.__file__), 'MTC_Logo.bmp')),
    image_width)
l.endorigin()

height += image_height + 5
l.origin(5, height)
l.write_barcode(height=80, barcode_type='C', check_digit='Y')
l.write_text(f'{HD_Serial}')
l.endorigin()

label = l.dumpZPL()
l.preview()

z = Zebra()
Q = z.getqueues()
z.setqueue(Q[0])
z.setup()
z.output(label)

关于python - 尝试使用 ZPL 到斑马打印机进行打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72885036/

相关文章:

python - 使用 lxml tostring() 获取原始字符串

javascript - jsPDF中是否有下划线setFontType?

c# - 如何验证 Zebra 打印机是否使用 ZPL 和 C# 成功打印(或能够检测错误)?

printing - ABCPDF 字体打印布局 - 取决于机器

php - 标签打印机在实际打印简单标签之前推进 8 个标签

vb.net - CPCL 语言的斑马条码打印示例

python - 什么工具可以在 Linux 中运行,为 Python 程序创建安装程序,然后在 Windows 上安装它?

python - 使用 Python 的 Selenium Webdriver : Avoiding multiple logins in my test

python - 您如何知道新列表是已创建还是刚刚修改?

html - chrome 在打印预览时截断页面内容,而其他浏览器则不会