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

Tabbed text #635

Open
1 task done
tmblog opened this issue Apr 11, 2024 · 8 comments
Open
1 task done

Tabbed text #635

tmblog opened this issue Apr 11, 2024 · 8 comments

Comments

@tmblog
Copy link

tmblog commented Apr 11, 2024

I have:

  • searched open and closed issues for duplicates

Cannot get tabbed text. It stays on the left I am trying achieve item left price right. But I wanted to see how the tab works first but I can't get it to go the the right. Any pointers would be highly appreciated.
Thank you

printer = Win32Raw()
printer.open()
printer.control("HT", count=8)
printer.text("tabbed text 8")

This prints left aligned - what am I missing?

Device info

Printer is Aures ODP 333 (it supports esc/pos HT command)

python-escpos version: 3.1

python version: 3.12.1

operating system: Windows 11

@gabri3l0
Copy link

@tmblog what was the steps to configure and test the printer on windows? could you help me please?

@Peppershade
Copy link

I have the same question. I tried with set align, but that doesn't seem to do the trick when applied to the same line

@belono
Copy link
Contributor

belono commented May 1, 2024

Hi and thanks for your question!

The way Epson ESC/POS handles horizontal tabs (HT) is:

  1. Inform the printer how to handle the character tab (number of tabs to be handled and length of each tab)
  2. Send text and tabs separately.

In python-escpos we do the above using the methods:

  1. .control("HT", count, tab_size)
  2. .text(...) and .text("\t")

So to get the following output (imagine underscores are spaces):

tabbed________text________8

You write:

p.control("HT", count=2, tab_size=8)  # handle 2 tabs of 8 characters size
p.text("tabbed")
p.text("\t")  # TAB nº1
p.text("text")
p.text("\t")  # TAB nº2
p.text("8")
p.ln()  # carriage return

Hope this helps.
Don't doubt to ask for help if you need it.
Cheers!

@tmblog
Copy link
Author

tmblog commented May 11, 2024

Hi and thanks for your question!

The way Epson ESC/POS handles horizontal tabs (HT) is:

1. Inform the printer how to handle the character tab (number of tabs to be handled and length of each tab)

2. Send text and tabs separately.

In python-escpos we do the above using the methods:

1. `.control("HT", count, tab_size)`

2. `.text(...)` and `.text("\t")`

So to get the following output (imagine underscores are spaces):

tabbed________text________8

You write:

p.control("HT", count=2, tab_size=8)  # handle 2 tabs of 8 characters size
p.text("tabbed")
p.text("\t")  # TAB nº1
p.text("text")
p.text("\t")  # TAB nº2
p.text("8")
p.ln()  # carriage return

Hope this helps. Don't doubt to ask for help if you need it. Cheers!

That's great thank you!
What method would you recommend to programmatically calculate the end of the paper so I can place the price for a bill.

@tmblog
Copy link
Author

tmblog commented May 11, 2024

@tmblog what was the steps to configure and test the printer on windows? could you help me please?

Hello I used the default printer without the pid and vid.
See this:

from escpos.printer import Win32Raw

def print_escpos_receipt():
    try:
        # Create a printer object and open connection to default printer
        printer = Win32Raw()
        printer.open()

        printer.set(normal_textsize=1, double_height=1, height=8, bold=1)
        printer.textln("Collection - duplicate #101")
        printer.ln(2)
        printer.set(normal_textsize=1, double_height=1, height=8)
        printer.textln("Processing on Tue 09 Apr 01:25AM")

And so on

@belono
Copy link
Contributor

belono commented May 14, 2024

What method would you recommend to programmatically calculate the end of the paper so I can place the price for a bill.

It depends.
If you just want to place a single line of text containing a price like the typical 'Total' or 'Amount: £XXX,XX' right-aligned text found in sales invoices, then the simplest way is .set(align="right") to set the printer to print right-aligned.

On the other had, the only way to know the "end" of the paper is to know the number of columns of the printer, but that value changes between models and also by the choice of the printer font (A or B), and other settings.
Hopefully, most of this information can be found in the capabilities database as long as the printer is on the list of supported printers and the capabilities database contains the data.

You can access the capabilities data of a printer by passing the profile parameter with the profile name when instantiating a connector, and getting the profile dictionary, or calling the profile methods. For example:

import escpos.printer as printer

p = printer.Dummy(profile="TM-T20II")
print(p.profile.profile_data)
n_cols = p.profile.get_columns(font="a")

You can then use this data to position the text with the help of tabs or other methods.

@tmblog
Copy link
Author

tmblog commented May 19, 2024

What method would you recommend to programmatically calculate the end of the paper so I can place the price for a bill.

It depends. If you just want to place a single line of text containing a price like the typical 'Total' or 'Amount: £XXX,XX' right-aligned text found in sales invoices, then the simplest way is .set(align="right") to set the printer to print right-aligned.

On the other had, the only way to know the "end" of the paper is to know the number of columns of the printer, but that value changes between models and also by the choice of the printer font (A or B), and other settings. Hopefully, most of this information can be found in the capabilities database as long as the printer is on the list of supported printers and the capabilities database contains the data.

You can access the capabilities data of a printer by passing the profile parameter with the profile name when instantiating a connector, and getting the profile dictionary, or calling the profile methods. For example:

import escpos.printer as printer

p = printer.Dummy(profile="TM-T20II")
print(p.profile.profile_data)
n_cols = p.profile.get_columns(font="a")

You can then use this data to position the text with the help of tabs or other methods.

Hi thank you for your help!
I was referring to having line items on a bill e.g. item on left and price on the right.
I found that letting python do that makes it much easier than configuring printer tabs etc.

white_space = " ";
text = "Item 1" + 32 * white_space + "£9.99"
# programmatically adjust white space based on paper width.

@belono
Copy link
Contributor

belono commented May 19, 2024

Hello!

Your question reminded me of issue #27, our oldest open issue, a few days ago. This inspired me to write a fix for this fairly common need and I hope to be ready to open a draft pull request in a few days.

My approach is to add a helper method that organizes a list of strings into columns of the same width. The main problem I'm facing is what to do when a string exceeds the column width. I have a few approaches in mind, but I have yet to explore them.

Greetings and stay tuned. ;-)

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

4 participants