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

huangapple go评论67阅读模式
英文:

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

问题

Python win32print模块

```python
            printMethod = 'RAW'
            printer = win32print.OpenPrinter(self._printerName)
            win32print.StartDocPrinter(printer, 1, ('自动打印作业', 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)

这是将字符串收据发送到打印机的逻辑。我已尝试通过utf-8、gb18030和big5对字符串进行编码,但它们都打印出随机字符而不是字符串中的中文字符。

我正在使用富士通FP2000打印机。他们的文档说明gb18030和big5都受支持。

欢迎提供任何见解,谢谢。

将utf-8编码的字符串写入.txt文件会产生正确的中文字符输出。但是,gb18030和big5会输出奇怪的字符。

使用big5/gb18030打印会产生相同的输出,看起来像是垂直拉伸的韩文字符。使用utf-8打印会产生"变异"的字母(AE组合在一起,带尾巴的o等等,希望你能理解我在这里指的是什么)。

根据打印机文档,它支持gb18030和big5。我还成功地从记事本中打印了中文字符,所以我知道打印机支持打印中文字符。


<details>
<summary>英文:</summary>

Python win32print module

```python
            printMethod = &#39;RAW&#39;
            printer = win32print.OpenPrinter(self._printerName)
            win32print.StartDocPrinter(printer, 1, (&#39;Automated printjob&#39;, None, &#39;RAW&#39;))
                    
            receipt = receipt.encode(&#39;big5&#39;)

            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

答案1

得分: 0

我的问题出在打印机配置上。我不得不手动更改预期的编码格式。

富士通FP2000打印机

  1. 按住进纸按钮并打开打印机电源
  2. 设置菜单 > 设置 > 打印 > 语言选择 > 简体中文
  3. 返回设置菜单 > 保存并退出
    打印机现在应该使用gb18030-2000编码(兼容简体中文字符)。
英文:

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)

huangapple
  • 本文由 发表于 2023年5月29日 15:19:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76355369.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定