Supported cryptocurrencies:
BTC BTC
BCH Bitcoin Cash
NANO NANO
XTZ Tezos
0.5 NANO
EnglishWhat's the correct way to send formatted text to thermal printer using python?

I am creating a mobile application using the python library Kivy. While the application is being used by the user, it collects some data from the user, put the data on a .pdf file, and then the pdf file is sent to the printer via bluetooth. One of the users is trying to send the file to a thermal printer 58mm (this one: https://produto.mercadolivre.com.br/MLB-1568901030-mini-impressora-portatil-bluetooth-termica-58mm-android-ios-_JM). What I want to know is what should I do to send the file on a format that is perfectly suited for a 58mm thermal printer? For example, I was trying to use the python library ESCPOS. from escpos import printer my_data = printer.Dummy() my_data.text('Business Name\n') print(my_data.output) >>> b'Business Name\n' This string stores all of the “output” as raw ESC/POS. What do I do now? Should I put this on a .txt file or should I save this output in what format to send this to the thermal printer? That's the issue, I don't know what I should do with this output exactly. I just want to make sure that I can format the text using this library (change font size, bold, italic text, QR code, image, etc), and then send it to the printer and have it printed correctly. I will pay 0.5 NANO for any suggestion that leads me to find what to do. Even if you are not sure if your idea will work, just suggest it to me, and if this helps me to accomplish what I'm wanting to achieve, I will be paying up to 2 NANO for you. It all depends on the size of your contribution. If you say step by step what to do, obviously I can pay more. I'm open to offers.

KivyLearner 3 years ago
    Tags:


Momo 3 years ago
i think word and pdf is suitable i was watching on youtube how to print food receipts on thermal printer on youtube and he use ms word and it work so I think you have to convert your txt file to word and then you can edit it as you want and print it by connecting your pc and the printer
KivyLearner 3 years ago
Thank you for your answer, I've sent you 0.0625 NANO; Yes, PDF is suitable, although I needed to use the python library fpdf to edit the .pdf file before sending to the thermal printer.
Dogan2134 3 years ago
you can write on the YouTube . can find more detal
solomon fei 3 years ago
It seems that the printer only supports a limited line length, and auto-wraps long lines.

If this is the printer in question, it has a print width of 72 mm, and three (I assume monospaced) fonts, with letter widths of 3 mm, 1.5 mm or 1.1 mm. That means you can have at most 24, 48 or 65 characters per line, depending on the font you pick (and assuming no side margins).

Please, check on this link also.....https://stackoverflow.com/questions/64858365/how-to-format-python-string-for-particular-pos-printer

https://github.com/python-escpos/python-escpos

https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=79
KivyLearner 3 years ago
Very good reference, solomon fei!
The thermal printer has 58mm width. I ended up using Arial font and different font sizes. With font size of 7.5, I got 46 characters on a single line. I am sending you 0.0625 NANO for your hints!
solomon fei 3 years ago
Thanks, and really appreciate it
Odaykh 3 years ago
I have experience printing to Zebra thermal printers (though that was with Ruby), and I assume the process is very similar for Epson printers. These sorts of printers expect "documents" to be in a very specific format, so they know what text size to use, how to display bar codes, that sort of thing. So there's two main parts to what you'll need to do, 1) converting whatever format you currently have into something the printer can understand, and 2) sending a document to the printer.

A little bit of googling led me here: https://github.com/python-escpos/python-escpos
Code available to your particular printer: https://reference.epson-biz.com/modules/...tent_id=79

I think the first step would be to take the example code from the python-escpos library, and use it to make "something" come out of the printer. Once you get that far, you can start to convert your documents into what the printer can use.
KivyLearner 3 years ago
I had a lot of troubles on using the python escpos library. It is hard to find the correct identifiers for this chinese thermal printer we have to start the connection through the python ESCPOS library.
I got it working using pdf formatted by the fpdf python library. I wasn't expecting it to be as simple as it is. Thanks for your help anyway, I'm sending 0.0625 NANO for your help!
fered dered 3 years ago
I think this will help you https://habr.com/ru/post/246989/
KivyLearner 3 years ago
Connecting to the printer directly through python code didn't work for me. That's why I ended up using Android intent to send the .pdf file formatted with fpdf python library directly to the printer, and it worked.
I'm sending some NANO for your help! Thanks
rj 3 years ago
i suppose phrase and pdf is suitable i was looking on youtube the way to print meals receipts on thermal printer on youtube and he use ms phrase and it work so I suppose you need to convert your txt record to phrase and then you can edit it as you need and print it by means of connecting your pc and the printer
KivyLearner 3 years ago
Thanks. Phrase didn't work but sending the .pdf file directly to the printer worked. But I needed to edit it using the python library fpdf.
I'm sending some NANO for your help, thanks rj!
Serdar Kaplan 3 years ago
https://www.youtube.com/watch?v=lIIqJDs7TQc
KivyLearner 3 years ago
Thanks for your help, but this was too basic. This is not a thermal printer. Not suited for mobile also. I'm sending some NANO as a reward for your effort.
Dayvson 3 years ago
Oi, sou brasileiro, tenho um artigo que te ajudará muito, o que acontece é que você precisa saber como a impressora funciona a questão da impressão, e como é sua formatação, para poder transformar seu arquivo no formato correto

https://www.devmedia.com.br/impressao-em-ecf-como-imprimir-em-impressoras-fiscais/10708
KivyLearner 3 years ago
Valeu, cara, mas esse post não realmente resolve meu problema em específico, pois estava tentando imprimir um documento enviando pra uma impressora térmica a partir de um aplicativo mobile escrito em python! Mas vou te recompensar pelo seu esforço e estou enviando um pouco de NANO pro seu endereço, obrigado!
Lordrian 3 years ago
I think it's good to use word and PDF in sending formatted to thermenal printer using python
KivyLearner 3 years ago
Yes, sending formatted PDF worked!
I needed to use the fpdf python library to format the file before sending it to the thermal printer using the Android intent. I'm sending a reward for your NANO address. Thanks
KivyLearner 3 years ago
Hello, everyone! Thanks you all for your contribution.

Although none of the answers actually worked for me, I found how to solve the issue yesterday. The first problem that occurred was that sending the .pdf file for the thermal printer resulted on a badly formatted text. That's why I thought I would need to send commands directly to the thermal printer using python-escpos, as various users pointed out. But this actually also didn't work for me.

So I discovered that I had to configure the .pdf file using the python library fpdf, setting the width and height of the page before sending the file to the thermal printer. The thermal printer accepted the pdf and its formatting once these configurations were put using the fpdf library.

I realized 8 people here answered me, and I want to reward you all, even if my solution has ended up being a little different. I want to maintain this community in good spirit and I am very glad that you all put some work into trying to help me.

Please, everyone that answered on this post, post your NANO address so I can pay you accordingly. I will pay everyone that answered me equally; I may pay slightly more for some people that seemed to put more effort on answering.

I will wait for your addresses, so please let me know your NANO address!
Bitfortip 3 years ago Correct
Hi, we will reply on your an email with their NANO addresses that they have on the platform.
KivyLearner 3 years ago
Thanks, I paid each one of them, proportional to how close the answer was to the true set of actions that leaded to the expected result I had. Awesome platform!