NielsLeenheer / ReceiptPrinterEncoder

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

Wordwrap is causing incorrect table header formatting #33

Closed madVis closed 3 weeks ago

madVis commented 3 weeks ago

Sample code:

Trying to print a table, here's the sample code:

const tableHeaderArray = [
      { width: 20, align: 'left' },
      { width: 7, align: 'left' },
      { width: 7, align: 'left' },
      { width: 7, align: 'right' },
      { width: 7, align: 'right' }
    ];

    const tableBodyArray = [
      [
        (encoder) => encoder.bold(true).text('Name').bold(false),
        (encoder) => encoder.bold(true).text('BigHeading').bold(false),
        (encoder) => encoder.bold(true).text('Qty').bold(false),
        (encoder) => encoder.bold(true).text('Net Amount').bold(false),
        (encoder) => encoder.bold(true).text('Net Total').bold(false)
      ],
      [
        'Banana',
        'doz',
        '2',
        '1.50',
        '3.00'
      ],
      [
        'Cherry',
        'kg',
        '1',
        '10.00',
        '10.00'
      ]
    ];

    encoder.table(tableHeaderArray, tableBodyArray);

Here's the print

IMG_0457

Expectation: All columns heading should be in the same line Actual: The second column heading "BigHeading" is moving to the next line

NielsLeenheer commented 3 weeks ago

Found the problem. Will be fixed in the next update.