esc_pos_printer icon indicating copy to clipboard operation
esc_pos_printer copied to clipboard

How to print vietnamese language?

Open ndhhaiduong opened this issue 4 years ago • 10 comments

Can i print vietnamese language?

I used code:

Uint8List  encVn =
    await CharsetConverter.encode("ISO-8859-1", 'Tiếng Việt, còn gọi tiếng Việt');
    ticket.textEncoded(encVn, styles: PosStyles(bold: true, align: PosAlign.center, codeTable: PosCodeTable.vietnam));

68638c3aa0c95a9703d8 esc_pos_printer: ^3.1.6 charset_converter: ^1.0.3 Printer: Xprinter

I found list charsets: I/flutter (28800): Adobe-Standard-Encoding I/flutter (28800): Big5 I/flutter (28800): Big5-HKSCS I/flutter (28800): BOCU-1 I/flutter (28800): CESU-8 I/flutter (28800): cp1363 I/flutter (28800): cp851 I/flutter (28800): EUC-JP I/flutter (28800): EUC-KR I/flutter (28800): GB18030 I/flutter (28800): GBK I/flutter (28800): hp-roman8 I/flutter (28800): HZ-GB-2312 I/flutter (28800): IBM-Thai I/flutter (28800): IBM00858 I/flutter (28800): IBM01140 I/flutter (28800): IBM01141 I/flutter (28800): IBM01142 I/flutter (28800): IBM01143 I/flutter (28800): IBM01144 I/flutter (28800): IBM01145 I/flutter (28800): IBM01146 I/flutter (28800): IBM01147 I/flutter (28800): IBM01148 I/flutter (28800): IBM01149 I/flutter (28800): IBM037 I/flutter (28800): IBM1026 I/flutter (28800): IBM1047 I/flutter (28800): IBM273 I/flutter (28800): IBM277 I/flutter (28800): IBM278 I/flutter (28800): IBM280 I/flutter (28800): IBM284 I/flutter (28800): IBM285 I/flutter (28800): IBM290 I/flutter (28800): IBM297 I/flutter (28800): IBM420 I/flutter (28800): IBM424 I/flutter (28800): IBM437 I/flutter (28800): IBM500 I/flutter (28800): IBM775 I/flutter (28800): IBM850 I/flutter (28800): IBM852 I/flutter (28800): IBM855 I/flutter (28800): IBM857 I/flutter (28800): IBM860 I/flutter (28800): IBM861 I/flutter (28800): IBM862 I/flutter (28800): IBM863 I/flutter (28800): IBM864 I/flutter (28800): IBM865 I/flutter (28800): IBM866 I/flutter (28800): IBM868 I/flutter (28800): IBM869 I/flutter (28800): IBM870 I/flutter (28800): IBM871 I/flutter (28800): IBM918 I/flutter (28800): ISO-2022-CN I/flutter (28800): ISO-2022-CN-EXT I/flutter (28800): ISO-2022-JP I/flutter (28800): ISO-2022-JP-1 I/flutter (28800): ISO-2022-JP-2 I/flutter (28800): ISO-2022-KR I/flutter (28800): ISO-8859-1 I/flutter (28800): ISO-8859-10 I/flutter (28800): ISO-8859-13 I/flutter (28800): ISO-8859-14 I/flutter (28800): ISO-8859-15 I/flutter (28800): ISO-8859-2 I/flutter (28800): ISO-8859-3 I/flutter (28800): ISO-8859-4 I/flutter (28800): ISO-8859-5 I/flutter (28800): ISO-8859-6 I/flutter (28800): ISO-8859-7 I/flutter (28800): ISO-8859-8 I/flutter (28800): ISO-8859-9 I/flutter (28800): KOI8-R I/flutter (28800): KOI8-U I/flutter (28800): macintosh I/flutter (28800): SCSU I/flutter (28800): Shift_JIS I/flutter (28800): TIS-620 I/flutter (28800): US-ASCII I/flutter (28800): UTF-16 I/flutter (28800): UTF-16BE I/flutter (28800): UTF-16LE I/flutter (28800): UTF-32 I/flutter (28800): UTF-32BE I/flutter (28800): UTF-32LE I/flutter (28800): UTF-7 I/flutter (28800): UTF-8 I/flutter (28800): windows-1250 I/flutter (28800): windows-1251 I/flutter (28800): windows-1252 I/flutter (28800): windows-1253 I/flutter (28800): windows-1254 I/flutter (28800): windows-1255 I/flutter (28800): windows-1256 I/flutter (28800): windows-1257 I/flutter (28800): windows-1258 I/flutter (28800): x-compound-text I/flutter (28800): x-ebcdic-xml-us I/flutter (28800): x-euc-tw-2014 I/flutter (28800): x-gsm-03.38-2009 I/flutter (28800): x-ibm-1047-s390 I/flutter (28800): x-ibm-1125_P100-1997 I/flutter (28800): x-ibm-1129_P100-1997 I/flutter (28800): x-ibm-1130_P100-1997 I/flutter (28800): x-ibm-1131_P100-1997 I/flutter (28800): x-ibm-1132_P100-1998 I/flutter (28800): x-ibm-1133_P100-1997 I/flutter (28800): x-ibm-1137_P100-1999 I/flutter (28800): x-ibm-1140-s390 I/flutter (28800): x-ibm-1141-s390 I/flutter (28800): x-ibm-1142-s390 I/flutter (28800): x-ibm-1143-s390 I/flutter (28800): x-ibm-1144-s390 I/flutter (28800): x-ibm-1145-s390 I/flutter (28800): x-ibm-1146-s390 I/flutter (28800): x-ibm-1147-s390 I/flutter (28800): x-ibm-1148-s390 I/flutter (28800): x-ibm-1149-s390 I/flutter (28800): x-ibm-1153-s390 I/flutter (28800): x-ibm-1154_P100-1999 I/flutter (28800): x-ibm-1155_P100-1999 I/flutter (28800): x-ibm-1156_P100-1999 I/flutter (28800): x-ibm-1157_P100-1999 I/flutter (28800): x-ibm-1158_P100-1999 I/flutter (28800): x-ibm-1160_P100-1999 I/flutter (28800): x-ibm-1162_P100-1999 I/flutter (28800): x-ibm-1164_P100-1999 I/flutter (28800): x-ibm-1250_P100-1995 I/flutter (28800): x-ibm-1251_P100-1995 I/flutter (28800): x-ibm-1252_P100-2000 I/flutter (28800): x-ibm-1253_P100-1995 I/flutter (28800): x-ibm-1254_P100-1995 I/flutter (28800): x-ibm-1255_P100-1995 I/flutter (28800): x-ibm-1256_P110-1997 I/flutter (28800): x-ibm-1257_P100-1995 I/flutter (28800): x-ibm-1258_P100-1997 I/flutter (28800): x-ibm-12712-s390 I/flutter (28800): x-ibm-12712_P100-1998 I/flutter (28800): x-ibm-1373_P100-2002 I/flutter (28800): x-ibm-1383_P110-1999 I/flutter (28800): x-ibm-1386_P100-2001 I/flutter (28800): x-ibm-16684_P110-2003 I/flutter (28800): x-ibm-16804-s390 I/flutter (28800): x-ibm-16804_X110-1999 I/flutter (28800): x-ibm-25546 I/flutter (28800): x-ibm-33722_P12A_P12A-2009_U2 I/flutter (28800): x-ibm-37-s390 I/flutter (28800): x-ibm-4517_P100-2005 I/flutter (28800): x-ibm-4899_P100-1998 I/flutter (28800): x-ibm-4909_P100-1999 I/flutter (28800): x-ibm-4971_P100-1999 I/flutter (28800): x-ibm-5123_P100-1999 I/flutter (28800): x-ibm-5351_P100-1998 I/flutter (28800): x-ibm-5352_P100-1998 I/flutter (28800): x-ibm-5353_P100-1998 I/flutter (28800): x-ibm-5478_P100-1995 I/flutter (28800): x-ibm-803_P100-1999 I/flutter (28800): x-ibm-813_P100-1995 I/flutter (28800): x-ibm-8482_P100-1999 I/flutter (28800): x-ibm-901_P100-1999 I/flutter (28800): x-ibm-902_P100-1999 I/flutter (28800): x-ibm-9067_X100-2005 I/flutter (28800): x-ibm-916_P100-1995 I/flutter (28800): x-IBM1006 I/flutter (28800): x-IBM1025 I/flutter (28800): x-IBM1097 I/flutter (28800): x-IBM1098 I/flutter (28800): x-IBM1112 I/flutter (28800): x-IBM1122 I/flutter (28800): x-IBM1123 I/flutter (28800): x-IBM1124 I/flutter (28800): x-IBM1153 I/flutter (28800): x-IBM1363 I/flutter (28800): x-IBM1364 I/flutter (28800): x-IBM1371 I/flutter (28800): x-IBM1388 I/flutter (28800): x-IBM1390 I/flutter (28800): x-IBM1399 I/flutter (28800): x-IBM33722 I/flutter (28800): x-IBM720 I/flutter (28800): x-IBM737 I/flutter (28800): x-IBM856 I/flutter (28800): x-IBM867 I/flutter (28800): x-IBM874 I/flutter (28800): x-IBM875 I/flutter (28800): x-IBM922 I/flutter (28800): x-IBM930 I/flutter (28800): x-IBM933 I/flutter (28800): x-IBM935 I/flutter (28800): x-IBM937 I/flutter (28800): x-IBM939 I/flutter (28800): x-IBM942 I/flutter (28800): x-IBM943 I/flutter (28800): x-IBM949 I/flutter (28800): x-IBM949C I/flutter (28800): x-IBM950 I/flutter (28800): x-IBM954 I/flutter (28800): x-IBM964 I/flutter (28800): x-IBM970 I/flutter (28800): x-IBM971 I/flutter (28800): x-IMAP-mailbox-name I/flutter (28800): x-iscii-be I/flutter (28800): x-iscii-gu I/flutter (28800): x-iscii-ka I/flutter (28800): x-iscii-ma I/flutter (28800): x-iscii-or I/flutter (28800): x-iscii-pa I/flutter (28800): x-iscii-ta I/flutter (28800): x-iscii-te I/flutter (28800): x-ISCII91 I/flutter (28800): x-ISO-2022-CN-CNS I/flutter (28800): x-iso-8859-11 I/flutter (28800): x-JavaUnicode I/flutter (28800): x-JavaUnicode2 I/flutter (28800): x-JIS7 I/flutter (28800): x-JIS8 I/flutter (28800): x-LMBCS-1 I/flutter (28800): x-mac-centraleurroman I/flutter (28800): x-mac-cyrillic I/flutter (28800): x-mac-greek I/flutter (28800): x-mac-turkish I/flutter (28800): x-MS950-HKSCS I/flutter (28800): x-UnicodeBig I/flutter (28800): x-UTF-16LE-BOM I/flutter (28800): x-UTF16_OppositeEndian I/flutter (28800): x-UTF16_PlatformEndian I/flutter (28800): x-UTF32_OppositeEndian I/flutter (28800): x-UTF32_PlatformEndian How can I fix it? Please give me any suggestions here. Thanks!

ndhhaiduong avatar May 16 '20 10:05 ndhhaiduong

@ndhhaiduong

Did you find any solution? I am having the same problem with Japanese characters. Please share if you have found any solution.

ghost avatar Jul 19 '20 04:07 ghost

I have same issue, I printed Thai.

HUANGLIWEN avatar Aug 07 '20 09:08 HUANGLIWEN

@ndhhaiduong

Did you find any solution? I am having the same problem with Japanese characters. Please share if you have found any solution.

I'm still having a problem.

ndhhaiduong avatar Aug 10 '20 05:08 ndhhaiduong

Do u found any solution?

ngdangduy13 avatar Dec 03 '20 05:12 ngdangduy13

hello @andrey-ushakov , any solution for this issue, or could i know the charset using with charset_converter to encode vietnamese text?

TungPT95 avatar Dec 03 '20 06:12 TungPT95

My solution in create an image from canvas and using draw image to print, here is an sample code to generate image as Uint8List :

Future<Uint8List> _generateImageFromString(
    String text,
    ui.TextAlign align,
  ) async {
    ui.PictureRecorder recorder = new ui.PictureRecorder();
    Canvas canvas = Canvas(
        recorder,
        Rect.fromCenter(
          center: Offset(0, 0),
          width: 550,
          height: 400, // cheated value, will will clip it later...
        ));
    TextSpan span = TextSpan(
      style: const TextStyle(
        color: Colors.black,
        fontSize: 20,
        fontWeight: ui.FontWeight.bold,
      ),
      text: text,
    );
    TextPainter tp = TextPainter(
        text: span,
        maxLines: 3,
        textAlign: align,
        textDirection: TextDirection.ltr);
    tp.layout(minWidth: 550, maxWidth: 550);
    tp.paint(canvas, const Offset(0.0, 0.0));
    var picture = recorder.endRecording();
    final pngBytes = await picture.toImage(
      tp.size.width.toInt(),
      tp.size.height.toInt() - 2, // decrease padding
    );
    final byteData = await pngBytes.toByteData(format: ui.ImageByteFormat.png);
    return byteData!.buffer.asUint8List();
  }

Now can print it using

final imageBytes = await _generateImageFromString(
      textToPrint,
      TextAlign.center,
    );
final posImage.Image? image = posImage.decodeImage(imageBytes);
printer.image(image!); 

Same solution apply to printRow...(long code and really ugly :v but it can do the job until official support release)

From my point of view, this solution has:

Advantages:

  • any fonts (google font....)
  • any languages.

Disadvantages:

  • not native-feeling with printer(the font, line spacing...)

nielsezeka avatar Jan 24 '22 02:01 nielsezeka

i found solution with capture image and send image to print. but it is not good solutions. some of the printer not support large length of image and become slow. anyone have solution?

iyashiyas avatar May 22 '22 15:05 iyashiyas

@nielsezeka hey, how would you change this solution to do a receipt layout? I believe it's what you meant by "Same solution apply to printRow..."

niyonx avatar Sep 08 '22 20:09 niyonx

@iyashiyas if you don't mind, do you use the screenshot class? I have tried using it but it prints really bad

niyonx avatar Sep 08 '22 20:09 niyonx

I faced same issues. Already tried with charset UTF-8 but it's not work

taida2203 avatar Oct 18 '23 10:10 taida2203