esc_pos_utils icon indicating copy to clipboard operation
esc_pos_utils copied to clipboard

Text alignment

Open niktses opened this issue 5 years ago • 8 comments

Texts are always aligned left. It is not updated through the text styling.

niktses avatar Mar 16 '20 11:03 niktses

Do you have a different output?

ticket.text('Center', styles: PosStyles(align: PosAlign.center));
ticket.text('Left');
ticket.text('Right', styles: PosStyles(align: PosAlign.right));
ticket.text('Left');

IMG_1069

andrey-ushakov avatar Mar 16 '20 11:03 andrey-ushakov

Yes everything is on the left

niktses avatar Mar 16 '20 11:03 niktses

This is what I have on an EPSON TM-T20iii with esc_pos_utils 0.4.9

test

johnvuko avatar Oct 09 '20 15:10 johnvuko

Same on Epson TM-m30, sometimes. Here are some test results

printDemoReceipt() seems to print correctly. testReceipt() immediately after printDemoReceipt() prints with all text centered

testReceipt() without printDemoReceipt() prints all text left justified, event text within a row:

printer.row([
        PosColumn(
          text: 'Align right',
          width: 12,
          styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2),
        ),
    ]);

testReceipt() with the image first prints all text centered, including the above row. This row prints correctly:

printer.row([
      PosColumn(
          text: 'Change',
          width: 8,
          styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
      PosColumn(
          text: '\$4.03',
          width: 4,
          styles: PosStyles(align: PosAlign.right, width: PosTextSize.size2)),
    ]);

tantzygames avatar Dec 28 '20 05:12 tantzygames

Getting same issue, when i use image PosAlign.center working but without image its not working. any solution?

patelnirav48 avatar Jan 05 '22 09:01 patelnirav48

I have found the a solution which is working fine with my TM-T70II. You can just insert the below code after line 35.

bytes += setStyles(PosStyles().copyWith(align: styles.align));

https://github.com/andrey-ushakov/esc_pos_utils/blob/master/lib/src/generator.dart#L351

I don't know why, but compare with function printer.image and printer.text, the problem is in file of generator.dart.

btw to make my TM-T70II, the maxCharsPerLine should change to 42 / 56

return (font == null || font == PosFontType.fontA) ? 42 : 56;

https://github.com/andrey-ushakov/esc_pos_utils/blob/master/lib/src/generator.dart#L37

and PaperSize should change to 512

int get width => value == PaperSize.mm58.value ? 372 : 512;

https://github.com/andrey-ushakov/esc_pos_utils/blob/master/lib/src/enums.dart#L41

ajiehust avatar Mar 05 '22 21:03 ajiehust

I have same issue, you can fix this by set style with align center first printer.setStyles(const PosStyles(align: PosAlign.center));

leanhtuan1994 avatar Dec 22 '22 09:12 leanhtuan1994

i have faced same issue here is the solution // Align left command in ESC/POS is ESC a 0 // ESC = 27, a = 97, 0 = left alignment bytes += [27, 97, 0]; bytes += generator.text('5552\n');

aliibrahimroshan avatar Nov 08 '23 00:11 aliibrahimroshan