ESC/POS Printing

Okay, here’s an example for you @pierre6. Also, the usual disclaimer - this is Bubble and JavaScript we’re talking about here so there’s probably half a dozen other ways you could get the same results:

Screen Shot 2022-04-13 at 9.40.46 PM

  1. We start with just some normal left-aligned text, which is the string ‘GRAND TOTAL:’

  2. We then insert a Bubble dynamic expression for this order’s Grand Total field. I wrapped it in apostrophes because padStart is a JavaScript string method and so we need to make it a string.

  3. The stuff inside the parentheses is just me calculating how many blank spaces to place before that dollar amount so that it goes all the way to the right edge of the receipt paper. If I already knew the number of spaces I needed then I could have just typed in a number.

You could read what’s inside the parentheses as "the total number of printable columns for my printer (I used a variable that I named ‘padding’ for whatever reason) minus the number of characters of whatever was to the left of this dollar amount."

Also, I could have specified some character for the padStart’s pad_string parameter but if nothing is specified then it just inserts blank spaces. Here’s an example where I use this parameter to make a horizontal line using = equal signs across the whole width of the receipt:
Screen Shot 2022-04-13 at 10.18.01 PM
The “newLine” variable is purely for my convenience; it’s easier to type than the ESC/POS command for a line break which is ‘\x0A’
Screen Shot 2022-04-13 at 10.29.29 PM

1 Like