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

Text alignment #9

Open niktses opened 4 years ago

niktses commented 4 years ago

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

andrey-ushakov commented 4 years ago

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

niktses commented 4 years ago

Yes everything is on the left

johnvuko commented 3 years ago

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

test

tantzygames commented 3 years ago

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)),
    ]);
patelnirav48 commented 2 years ago

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

ajiehust commented 2 years ago

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

leanhtuan1994 commented 1 year ago

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

aliibrahimroshan commented 11 months ago

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');