[Epson ESCPOS使用ESC R n命令打印丹麦字符

问题描述 投票:0回答:1

我正在使用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)

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

python-3.x epson pos escpos
1个回答
0
投票

暂时,您可能想尝试的是将下面的编码规范从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调用发送此类数据。

© www.soinside.com 2019 - 2024. All rights reserved.