For the time being, what you might want to try is to change the encoding specification below from utf-8 to cp865.
rawdata = bytes('Print æ,ø,å', 'utf-8') + b'\n' + b'\x1d\x56' + six.int2byte(66) + b'\x00' #print
If that doesn't work, you should stop using win32print and switch to pyserial.
It is also necessary to switch the printer mode, uninstall the Advanced Printer Driver, and install the printer serial port driver.
Then the application program needs to create all the print data using the raw ESC/POS commands.
The reason is as follows.
You can get the Advanced Printer Driver of TM-T20II and manual & sample program here.
EPSON Advanced Printer Driver for TM-T20II
According to the sample program "Step 1 Printing Device Font", in order to send a raw ESC/POS command to the printer, it is necessary to select a specific device font.
Prints "Hello APD" with a device font and autocuts a receipt.
The core of the sample source in C ++ is as follows.
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();
Here's what it looks like in 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
Isn't it very difficult or impossible to port these to Python's win32print?
The win32print API doesn't seem to have the ability to customize fonts in the middle of printing.
Module win32print
And StartDocPrinter and WritePrinter have the following explanation.
win32print.StartDocPrinter
Note that the printer driver might ignore the requested data type.
win32print.WritePrinter
Suitable for copying raw Postscript or HPGL files to a printer.
The ESC/POS command is not raw PostScript or HPGL, and EPSON's Advanced Printer Driver does not necessarily send such data with a win32print call.