我需要把escpos发送到热敏收据打印机。我遇到了指定字符大小的问题,这在[https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=34]中有描述。在Python中,我将此命令编写为
#ESC @ for initiate the printer
string = b'\x1b\x40'
#GS ! command in the doc corresponding to 4 times character height and width
string = string + b'\x1d' + b'\x21' + b'\x30' + b'\x03'
string = string + bytes('hello world')在第一行中,我启动了与ESC @对应的打印机。在第二行中,我希望将字符大小指定为高度和宽度的4倍(请参阅文档的链接)。在第三行中,我打印出文本。
问题是打印出来的文本有4倍宽,而不是4倍高。我还尝试将字符大小写为两个命令
string = string + b'\x1d' + b'\x21' + b'\x30'
string = string + b'\x1d' + b'\x21' + b'\x03' 在这种情况下,我的文本以4倍的高度打印出来,而不是4倍的宽度。我很确定我读错了文档,但是我不知道我还应该怎么写命令来达到4倍的高度和宽度。
还有为GS提供的examples!在escpos中的语法,在那里它似乎写成GS!0x11,以达到2倍的宽度和高度。从表中看,这似乎没有什么意义。我知道python-escpos是存在的,但是它不能在我的usb打印机的windows10上工作。
发布于 2020-01-24 06:13:07
从文档上看,在我看来,你必须使用
b'\x1d' + b'\x21' + b'\x33' 在高度和宽度上都能放大4倍。两个'3‘表示放大倍数减一。第一个是宽度,第二个是高度。
所以问题似乎是你把宽度和高度分成了两个字节。它们应该被收集到一个字节中。
所以,总而言之:
#ESC @ for initiate the printer
string = b'\x1b\x40'
#GS ! command in the doc corresponding to 4 times character height and width
string = string + b'\x1d' + b'\x21' + b'\x33'
string = string + bytes('hello world')或者,以另一种方式:
def initialize():
# Code for initialization of the printer.
return b'\x1b\x40'
def magnify(wm, hm):
# Code for magnification of characters.
# wm: Width magnification from 1 to 8. Normal width is 1, double is 2, etc.
# hm: Height magnification from 1 to 8. Normal height is 1, double is 2, etc.
return bytes([0x1d, 16*(wm-1) + (hm-1)])
def text(t, encoding="ascii"):
# Code for sending text.
return bytes(t, encoding)
string = initialize() + magnify(4, 4) + text('hello world')https://stackoverflow.com/questions/59887559
复制相似问题