Comments (8)
Hi and thanks for your question!
The way Epson ESC/POS handles horizontal tabs (HT) is:
- Inform the printer how to handle the character tab (number of tabs to be handled and length of each tab)
- Send text and tabs separately.
In python-escpos we do the above using the methods:
.control("HT", count, tab_size)
.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!
from python-escpos.
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. ;-)
from python-escpos.
@tmblog what was the steps to configure and test the printer on windows? could you help me please?
from python-escpos.
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
from python-escpos.
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 returnHope 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.
from python-escpos.
@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
from python-escpos.
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.
from python-escpos.
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.
from python-escpos.
Related Issues (20)
- Text size not working (width and height) HOT 11
- Image printing prints only garbage HOT 29
- Barcode not printed HOT 4
- Introduce IntEnum or similar for printer states
- Usb printer not working on web Application HOT 2
- Printer not found on web application HOT 1
- Font switching not working. HOT 3
- is_online() fails with raise NotImplementedError()
- Full cut not working on Epson TM-T20III HOT 2
- 'usb timeout error' when used on a raspberry pi 3 with a cheap POS-58 thermal printer HOT 5
- ImportError: cannot import name 'DeviceNotFoundError' from 'escpos.exceptions' HOT 2
- usb.core.USBError: [Errno 5] Input/Output Error` HOT 1
- EPSON TM-m30III randomly fails to print images HOT 1
- Arabic Text not printing correctly HOT 2
- windows Invalid endpoint address HOT 1
- Printer Emulator Connection Issue HOT 6
- How to print big5 charcode HOT 1
- CLI not working for CupsPrinter, LP and Win32Raw connectors
- Print to a bluetooth device via rfcomm and printer.File() HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-escpos.