Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How write line with justification on the same line ? #43

Open
mazero opened this issue Apr 16, 2021 · 4 comments
Open

How write line with justification on the same line ? #43

mazero opened this issue Apr 16, 2021 · 4 comments

Comments

@mazero
Copy link

mazero commented Apr 16, 2021

Hello,

How write a line with justification on the left (ex. quantity, product title) and on the same line but with a justification on the right the price ?
When i use setjustification & writeline that's alaways make a break line.

Ex
this.ticket.forEach((product) => { print .setJustification('left').writeLine(${product.quantity}x ${product.title}).setJustification('right').writeLine(${product.price}); });

@mazero mazero changed the title How write line with justification on the same line How write line with justification on the same line ? Apr 16, 2021
@mcvendrell
Copy link
Contributor

You cannot do that.

You can only justify the same line with one property: left, right or middle, but will apply for all the line.

To do what you want, you must "build" you line with spaces in the right places, and know the width of the paper.

Example: for a printer with 48 cols

const unitsText = 'uds'.padEnd(3);
const nameText = 'description'.padEnd(22);
const priceText = 'price'.padStart(10);
const totalText = 'amount'.padStart(10);
this.printService
  .setJustification('left')
  .writeLine(unitsText + ' ' + nameText + ' ' + priceText + ' ' + totalText)
  .writeLine(''.padStart(48, '-'));

@mazero
Copy link
Author

mazero commented May 6, 2021

That's works. Thanks

@mazero mazero closed this as completed May 6, 2021
@mazero
Copy link
Author

mazero commented Oct 31, 2023

Another little hitch, do you have a solution for products with long product names? I have customers who have products with long names (i.e. lots of characters) and this shifts the price.

Does anyone have a tip?
Thanks in advance.

@mazero mazero reopened this Oct 31, 2023
@mcvendrell
Copy link
Contributor

There is not, exactly, a "solution" for this kind of problem. If the name is too long... it's too long. You can "short" it to a fixed length to avoid shifting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants