所以我尝试使用 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/