andrey-ushakov / esc_pos_utils

Basic Flutter/Dart classes for ESC/POS printing
BSD 3-Clause "New" or "Revised" License
147 stars 329 forks source link

Chinese strings are not supported #27

Open Dukro opened 3 years ago

Dukro commented 3 years ago

icket.text('简体中文', styles: PosStyles( height: PosTextSize.size2, width: PosTextSize.size2, )); Invalid argument (string): Contains invalid characters.: "简体中文"

c786909486 commented 3 years ago

icket.text('简体中文', styles: PosStyles( height: PosTextSize.size2, width: PosTextSize.size2, containsChinese: true ));

waqadArshad commented 1 year ago

You need to go to capabilities.json -- for me the path was: C:\Flutter\flutter 3.3.1\flutter.pub-cache\hosted\pub.dartlang.org\esc_pos_utils-1.1.0\lib\resources). This is the package file.

The default section looks like this:

image

And in the default section, add the following in the codePages map:

 "253": "UTF-8",

Now in the file it would look something like this:

image

after this, go to your flutter code and add this:

    final profile = await CapabilityProfile.load(name: 'default');
    final generator = Generator(PaperSize.mm80, profile);
    bytes += generator.setGlobalCodeTable('UTF-8');

after that add the following package in your pubspec.yaml file:

charset_converter: ^2.1.1

now, do something like this:

bytes += generator.textEncoded(
        await CharsetConverter.encode("UTF-8", 'Size 1 Product 1: 招牌韮黃鍋貼 , Signature: Pork W/ Yellow Chive'),
        styles: const PosStyles(align: PosAlign.left, bold: true));

Remember to use UTF-8 and also remember to use this same encoding setting for your printer:

image

waqadArshad commented 1 year ago

Hi, if you don't want to bother with that, you can use my fork:

https://github.com/waqadArshad/esc_pos_utils

as:

  esc_pos_utils:
    git:
      url: https://github.com/waqadArshad/esc_pos_utils.git

and if it fixes your issue, please remember to STAR the repo.