pythoncharacter-encodingpywin32thermal-printer

Printing of Chinese Characters to printer results in weird characters despite using UTF-8, GB18030, or BIG5 character encodings


Python win32print module

            printMethod = 'RAW'
            printer = win32print.OpenPrinter(self._printerName)
            win32print.StartDocPrinter(printer, 1, ('Automated printjob', None, 'RAW'))
                    
            receipt = receipt.encode('big5')

            win32print.StartPagePrinter(printer)
            win32print.WritePrinter(printer, receipt)
            win32print.WritePrinter(printer, self._cmd.fullCut)
            win32print.EndPagePrinter(printer)
            win32print.EndDocPrinter(printer)
            win32print.ClosePrinter(printer)

This is my logic to send a string receipt to the printer. I've attempted to encode the string via utf-8, gb18030, and big5 but all of them prints out random characters instead of the chinese character in the string.

I am using Fujitsu FP2000 printer. Their documentation states that both gb18030 and big5 are supported.

All insights are welcome, thanks.

Writing utf-8 encoded string to a .txt files results in the correct chinese character output. However, gb18030 and big5 outputs weird characters.

Printing with big5/gb18030 results in the same output, kind of looks like korean characters stretched vertically. Printing with utf-8 results in 'mutated' alphabets(AE combined together, o with a tail etc. hopefully you can understand what I am referring to here)

According to the printer docs, it supports both gb18030 and big5. I've also successfully printed chinese characters from the notepad so i know that the printer supports printing of chinese characters


Solution

  • My issue was in the printer configuration. I had to manually change the expected encoding format.

    Fujitsu FP2000 printer

    1. Hold feed button and power on printer
    2. Setup menu > settings > print > language selection > simplified chinese
    3. return to setup menu > save and end Printer should now be using gb18030-2000 encoding (simplified chinese character compatible)