【问题标题】:Epson ESCPOS print Danish character using ESC R n commandEpson ESCPOS 使用 ESC R n 命令打印丹麦语字符
【发布时间】:2020-08-09 05:02:35
【问题描述】:

我使用的是 Epson TM-T20II 热敏收据打印机,我需要打印带有丹麦字符(æ、ø、å)的收据。用于字符语言选择的 ESCPOS 代码描述为here。我的 Python 代码如下

import win32print
import six
#create some raw data
rawdata = b'\x1b\x40' #Instantiate the printer ESC @
rawdata = rawdata + b'\x1b\x52\x10' #Select the Danish II character set as in documentation ESC R 
where n = 10
rawdata = bytes('Print æ,ø,å', 'utf-8') + b'\n' + b'\x1d\x56' + six.int2byte(66) + b'\x00' #print 
some text and cut

#Creating the printing job in Windows 10 and send the raw text to the printer driver
printer = win32print.OpenPrinter('EPSON TM-T20II Receipt')
hJob = win32print.StartDocPrinter(printer, 1, ("Test print", None, "RAW"))
win32print.WritePrinter(printer, rawdata)
win32print.EndPagePrinter(printer)
win32print.ClosePrinter(printer)

我的问题是打印出一些奇怪的字符。我还通过按住进纸按钮并打开打印机电源将打印机设置为丹麦 II。我错过了什么?

【问题讨论】:

  • 您希望 TM-T20II 用作 Windows 标准桌面页面打印机吗?如果没有,请将打印机更改为串口模式,重新安装设备驱动程序,并发送带有pyserialpython-escpos的ESC/POS命令。
  • 没有。我知道 python-escpos,但它并没有我的所有需求。例如,据我所知,python-escpos 不支持丹麦语字符。
  • 如果 python-escpos 缺少功能,您应该修改它以添加功能,或者切换到 pyserial 并自己创建和发送所有 ESCPOS 命令。使用pyserial与使用原始模式下您在问题中编写的win32print不一样吗?

标签: python-3.x epson pos escpos


【解决方案1】:

目前,您可能想尝试将下面的编码规范从 utf-8 更改为 cp865

rawdata = bytes('Print æ,ø,å', 'utf-8') + b'\n' + b'\x1d\x56' + six.int2byte(66) + b'\x00' #print  

如果这不起作用,您应该停止使用 win32print 并切换到 pyserial。
还需要切换打印机模式,卸载高级打印机驱动,安装打印机串口驱动。
然后应用程序需要使用原始 ESC/POS 命令创建所有打印数据。

原因如下。


您可以在这里获取TM-T20II的高级打印机驱动程序和手册和示例程序。
EPSON Advanced Printer Driver for TM-T20II

根据示例程序“步骤 1 打印设备字体”,为了向打印机发送原始 ESC/POS 命令,需要选择特定的设备字体。

使用设备字体打印“Hello APD”并自动剪切收据。

C++中示例源码的核心如下。

CDC dc;
/*
 * Create the device context for the printer
 */
if(! dc.CreateDC(EPS_DRIVER_NAME, EPS_PRINTER_NAME, NULL, NULL) )
{
    AfxMessageBox(_T("Printer is not available."));
    return;
}

dc.StartDoc(&di);

/*
 * Perform the printing of the text
 */
CFont font, *old;
font.CreatePointFont(95, "FontA11", &dc);
old = dc.SelectObject(&font);
dc.TextOut(20, 10, "Hello APD!");
dc.SelectObject(old);
font.DeleteObject();

dc.EndPage();
dc.EndDoc();
dc.DeleteDC();

这是它在 VB 中的样子。

Dim printFont As New Font("Lucida Console", 8, FontStyle.Regular, GraphicsUnit.Point) ' Substituted to FontA Font

e.Graphics.PageUnit = GraphicsUnit.Point

' Print the string at 6,4 location using FontA font.
e.Graphics.DrawString("Hello APD!", printFont, Brushes.Black, 6, 4)

' Indicate that no more data to print, and the Print Document can now send the print data to the spooler.
e.HasMorePages = False

将这些移植到 Python 的 win32print 是不是非常困难或不可能?
win32print API似乎没有在打印过程中自定义字体的能力。
Module win32print

而StartDocPrinter和WritePrinter有如下解释。
win32print.StartDocPrinter

请注意,打印机驱动程序可能会忽略请求的数据类型。

win32print.WritePrinter

适合将原始 PostscriptHPGL 文件复制到打印机。

ESC/POS 命令不是原始 PostScript 或 HPGL,EPSON 的高级打印机驱动程序不一定通过 win32print 调用发送此类数据。

【讨论】:

    猜你喜欢
    • 2015-12-23
    • 2021-12-18
    • 1970-01-01
    • 2018-12-30
    • 2018-03-18
    • 1970-01-01
    • 2021-04-12
    • 2015-03-25
    • 2020-01-09
    相关资源
    最近更新 更多