tr3v3r / react-native-esc-pos-printer

An unofficial React Native library for printing on an EPSON TM printer with the Epson ePOS SDK for iOS and Epson ePOS SDK for Android
MIT License
169 stars 70 forks source link

Setting language to Japanese prints strange characters #54

Closed TwenLeMammouth closed 1 year ago

TwenLeMammouth commented 2 years ago

Hi, we are trying to print receipt in Japanese, but we only get some katakana and some shapes that shouldn't be here. await EscPosPrinter.init({ target: printer.target, seriesName: getPrinterSeriesByName(printer.name), language: 'EPOS2_LANG_JA', }) Using language: 'EPOS2_LANG_MULTI', didn't work either. ( I thought I needed that to print japanese and english characters..) Printing Japanese character works very well with the Epson app.

Screen Shot 2022-04-20 at 12 08 38
tr3v3r commented 2 years ago

Hello? Unfortunately I don’t have access to printer device now so I can’t test and fix it.

Have you tried to print another language ? Let’s say Chinese?

As a workaround you can use .data printing method and encode text manually with Japanese codepage. You can encode using https://www.npmjs.com/package/esc-pos-encoder#codepage this lib.

I.e.

let result = encoder .codepage('windows1251') .text('Iñtërnâtiônàlizætiøn') .codepage('cp936') .text('简体中文') .encode()

printing

// your printing commands .data(result) // your printing commands

.sendData()

Hope this helps

tr3v3r commented 2 years ago

@TwenLeMammouth have you resolved the issue?

TwenLeMammouth commented 2 years ago

Yes, this is resolved, but not with the encoder.. There is some hardcoded english 'EPOS2_LANG_ANK', but I can't remember where, which sets the language to English. So changing the printer language doesn't work when you use 'EscPosPrinter.init()'.

But I now have another problem, I had to plug a second printer, and with '.discover()' it can find both, but one by one, I never get an array with both printers in it.. I tried to connect them both in ethernet, and both bluetooth, and also one Ethernet and one bluetooth.

tr3v3r commented 2 years ago

@TwenLeMammouth you are talking about iOS and discovery?

TwenLeMammouth commented 2 years ago

I'm talking about this: const printers = await EscPosPrinter.discover() And yes, running on iOS.

tr3v3r commented 2 years ago

we have a bug for iOS

Could you please try to discover with this code?

import {
  NativeModules,
  NativeEventEmitter,
} from 'react-native';

const { EscPosPrinter, EscPosPrinterDiscovery } = NativeModules;

const discoveryEventEmmiter = new NativeEventEmitter(EscPosPrinterDiscovery);

discoveryEventEmmiter.addListener(
          'onDiscoveryDone',
          (printers) => {
            console.log(printers) 
          }
        );

EscPosPrinterDiscovery.discover(params)
TwenLeMammouth commented 2 years ago

I can see every printers with this, thank you ! But I have a stupid question.. What needs to be pass as params in the last line...?

tr3v3r commented 2 years ago

@TwenLeMammouth you can skip it. It's optional. But if you're interested you can read here https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/API.md#discoverparams

Rehankhalil462 commented 1 year ago

we have a bug for iOS

Could you please try to discover with this code?

import {
  NativeModules,
  NativeEventEmitter,
} from 'react-native';

const { EscPosPrinter, EscPosPrinterDiscovery } = NativeModules;

const discoveryEventEmmiter = new NativeEventEmitter(EscPosPrinterDiscovery);

discoveryEventEmmiter.addListener(
          'onDiscoveryDone',
          (printers) => {
            console.log(printers) 
          }
        );

EscPosPrinterDiscovery.discover(params)

@tr3v3r I am using Expo Development Client for React Native. I tried to access these { EscPosPrinter, EscPosPrinterDiscovery } from

const { EscPosPrinter, EscPosPrinterDiscovery } = NativeModules;

but I could not. How can i do this as I am not using Xcode for ios.

tr3v3r commented 1 year ago

fixed in v.3.0.0

https://github.com/tr3v3r/react-native-esc-pos-printer/releases/tag/vv3.0.0

doufu060514 commented 9 months ago

@TwenLeMammouth May i please ask how did you resolve the language issue? As i am facing the same situation. Could only print english properly, failed with EPOS2_LANG_JA, EPOS2_LANG_ZH_CN, EPOS2_LANG_ZH_TW a9294f772cd6a97cdd2e71807a75db89

TwenLeMammouth commented 8 months ago

As I said in a message before, there was some hardcoded english settings, in some shady files(for me) in the library, writen in a language I don't know. Maybe you can try to search all the files for this parameter "EPOS2_LANG_ANK". I'm sorry I don't think I can help more, it was 2 years ago, I don't have access to a printer anymore.

In the end, this issue shouldn't be closed if it was fixed only on my side and not on the library..