Python Forum
printing a text file by python and thermal printer
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing a text file by python and thermal printer
#1
hello friends 
i want to print a text file by a thermal printer(epson TM-T20) and by using python code...
i am going to use python-escpos or python-printer-escpos module for writing python code...

i have searched alot in these modules' documents..i found commands for printing a text inside python but i didn't find anything about printing a text file outside of python
please guide me Rolleyes
should i convert my text file to a special file type ?
Reply
#2
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.
Reply
#3
(Jul-28-2017, 06:56 PM)nilamo Wrote: 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.

i appreciate for your links..i found python-escpos library myself..but there is not any content about printing a file or a document...
i want to know what format i should convert my file???
Reply
#4
i have attached a thermal printer to my raspberry...i used usb port and found idproduct and idvendor and inputendpoint and outputendpoint by lsusb -D....
i used python-printer-escpos module
my code is :
from escpos.connections import getUSBPrinter


printer = getUSBPrinter()(idVendor=0x0483,
                          idProduct=0x5720,
                          inputEndPoint=0x81,
                          outputEndPoint=0x01) # Create the printer object with the connection params

printer.text("Hello World")
printer.lf()
 for setting up it...but i get the following error
Traceback (most recent call last):
  File "/home/pi/start/printerr/poss/NEW/py-print-escposs.py", line 8, in <module>
    outputEndPoint=0x01) # Create the printer object with the connection params
  File "/usr/local/lib/python3.4/dist-packages/escpos/connections.py", line 87, in __init__
    self.__open()
  File "/usr/local/lib/python3.4/dist-packages/escpos/connections.py", line 106, in __open
    if self._device.is_kernel_driver_active(0):
  File "/usr/local/lib/python3.4/dist-packages/usb/core.py", line 1061, in is_kernel_driver_active
    self._ctx.managed_open()
  File "/usr/local/lib/python3.4/dist-packages/usb/core.py", line 102, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python3.4/dist-packages/usb/core.py", line 120, in managed_open
    self.handle = self.backend.open_device(self.dev)
  File "/usr/local/lib/python3.4/dist-packages/usb/backend/libusb1.py", line 786, in open_device
    return _DeviceHandle(dev)
  File "/usr/local/lib/python3.4/dist-packages/usb/backend/libusb1.py", line 643, in __init__
    _check(_lib.libusb_open(self.devid, byref(self.handle)))
  File "/usr/local/lib/python3.4/dist-packages/usb/backend/libusb1.py", line 595, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 13] [b]Access denied[/b] (insufficient permissions)
what is the problem?
Reply
#5
Isn't this a continuation of a previous thread?
Reply
#6
hello friends...
i want to setup a thermal printer by python-printer-escpos module...
my code is :
from escpos.connections import getUSBPrinter printer = getUSBPrinter()(idVendor=0x0483, idProduct=0x5720, inputEndPoint=0x81, outputEndPoint=0x01) # Create the printer object with the connection params printer.text("Hello World") printer.lf()
 iget this error :
 
Traceback (most recent call last): File "/home/pi/start/printerr/poss/NEW/py-print-escposs.py", line 8, in <module> outputEndPoint=0x01) # Create the printer object with the connection params File "/usr/local/lib/python2.7/dist-packages/escpos/connections.py", line 89, in __init__ self.initialize() File "/usr/local/lib/python2.7/dist-packages/escpos/commandset/generic.py", line 463, in initialize self.__write(self.__class__.__ESC + '@') AttributeError: USBPrinter instance has no attribute '_Generic__write'
what is problem?????
please help
i need it instantly
Reply
#7
repost/fix your original post with proper indentation and new lines.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Replace a text/word in docx file using Python Devan 4 3,427 Oct-17-2023, 06:03 PM
Last Post: Devan
  save values permanently in python (perhaps not in a text file)? flash77 8 1,235 Jul-07-2023, 05:44 PM
Last Post: flash77
  Trying to send file to printer with no results. chob_thomas 2 3,384 Dec-21-2022, 07:12 AM
Last Post: Pedroski55
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,128 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  How do you marshal the default printer setup to print? hammer 0 1,283 May-29-2022, 02:54 PM
Last Post: hammer
  Can you print a string variable to printer hammer 2 1,956 Apr-30-2022, 11:48 PM
Last Post: hammer
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,679 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 6,999 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Printing x values from an csv file hobbyist 7 3,989 Mar-10-2021, 02:00 PM
Last Post: hobbyist
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,362 Dec-23-2020, 08:04 AM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020