NielsLeenheer / ReceiptPrinterEncoder

Create a set of commands that can be send to any receipt printer that supports ESC/POS, StarLine or StarPRNT
MIT License
183 stars 17 forks source link

Alignment and Codepage issues when creating tables #29

Closed cervantes-x closed 2 months ago

cervantes-x commented 2 months ago

I'm experiencing issues with text alignment in tables and codepage settings not being respected when generating a receipt using the latest version of the library. The table layout does not align correctly, and the specified codepage appears to be ignored.

Code Example:

const encoder = new ReceiptPrinterEncoder({
  columns: 48,
  printerModel: "pos-5890",
});

const result = encoder
  .initialize()
  .codepage("windows1252")
  .align("center");

result.table(
  [
    { width: 36, marginRight: 2, align: "left" },
    { width: 10, align: "right" },
  ],
  [
    ["Item 1", "€ 10,00"],
    ["Item 2", "15,00"],
    ["Item 3", "9,95"],
    ["Item 4", "4,75"],
    ["Item 5", "211,05"],
    ["Total", "€ 250,75"],
  ],
);

const encoded = result.encode();

sendToPrinter(encoded, printer);

Expected Behavior:

The table should align text as specified (left for the first column, right for the second). The windows1252 codepage should be applied for proper character encoding.

Actual Behavior:

The text in the second column of the table is not correctly aligned (should be right-aligned). The codepage setting does not seem to take effect, leading to incorrect character encoding.

Here is a screenshot of the incorrect output:

211,05-01

NielsLeenheer commented 2 months ago

I'm seeing the same with your example, but not in my own table code I used to test version 3. Weird. I'm looking into it.

NielsLeenheer commented 2 months ago

Should be fixed in release 3.0.1