### Install python-qrcode Source: https://github.com/python-escpos/python-escpos/wiki/Raspberry-Pi Clones the python-qrcode repository from GitHub, builds, and installs the library. ```bash # git clone https://github.com/lincolnloop/python-qrcode # cd python-qrcode # python setup.py build # sudo python setup.py install ``` -------------------------------- ### Install python-escpos Package Source: https://github.com/python-escpos/python-escpos/wiki/Installation Clone the python-escpos repository from GitHub, navigate into the directory, build the package, and then install it using `setup.py`. ```bash # cd python-escpos # python setup.py build # sudo python setup.py install ``` -------------------------------- ### Install python-escpos with all dependencies Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/installation.rst Use this command to install the python-escpos library along with all available dependencies for your platform. ```bash pip install python-escpos[all] ``` -------------------------------- ### Install Raspbian Packages Source: https://github.com/python-escpos/python-escpos/wiki/Raspberry-Pi Installs essential Python imaging, serial, and setuptools packages on Raspbian using apt-get. ```bash # apt-get install python-imaging python-serial python-setuptools ``` -------------------------------- ### Install Ubuntu Base Dependencies Source: https://github.com/python-escpos/python-escpos/wiki/Dependencies Installs Python imaging and serial libraries on Ubuntu using apt-get. ```bash # apt-get install python-imaging pyserial ``` -------------------------------- ### File Printer Configuration Example Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Example of a configuration file section for a File printer, specifying the device file and printer profile. ```yaml printer: type: File devfile: /dev/someprinter profile: TM-U220 ``` -------------------------------- ### Build and Install pyusb on Ubuntu Source: https://github.com/python-escpos/python-escpos/wiki/Dependencies Manually builds and installs the pyusb Python binding for libusb-1.0 from a tarball. ```bash # tar zxvf pyusb-1.*.tar.gz # cd pyusb-1.* # python setup.py build # sudo python setup.py install ``` -------------------------------- ### Network Printer Configuration Example Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Example of a configuration file section for a Network printer, specifying the host, port, and printer profile. ```yaml printer: type: Network host: 127.0.0.1 port: 9000 profile: TM-U220 ``` -------------------------------- ### Install python-escpos Source: https://github.com/python-escpos/python-escpos/wiki/Raspberry-Pi Clones the python-escpos repository, builds, and installs the library. This step is required after installing PyUSB for libusb-1.0. ```bash # git clone https://github.com/manpaz/python-escpos.git # cd python-escpos # python setup.py build # sudo python setup.py install ``` -------------------------------- ### Install Fedora Dependencies Source: https://github.com/python-escpos/python-escpos/wiki/Dependencies Installs necessary Python imaging, serial, and USB libraries on Fedora using yum. ```bash # yum install python-imaging pyserial pyusb python-qrcode ``` -------------------------------- ### Get Configured Printer Instance Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Load the configuration and retrieve the configured printer instance. ```python from escpos import config c = config.Config() printer = c.printer() ``` -------------------------------- ### Download and Install PyUSB Source: https://github.com/python-escpos/python-escpos/wiki/Raspberry-Pi Manually downloads, decompresses, builds, and installs PyUSB version 1.0 from a tarball. This is necessary when PyUSB 1.0 is not available through standard package managers. ```bash # wget ... # unzip pyusb*.zip # cd pyusb* # python setup.py build # sudo python setup.py install ``` -------------------------------- ### USB Printer Basic Usage Source: https://github.com/python-escpos/python-escpos/blob/master/README.rst Example demonstrating basic text, image, and barcode printing to a USB printer. Requires specifying USB vendor and product IDs, and a printer profile. ```python from escpos.printer import Usb """ Seiko Epson Corp. Receipt Printer (EPSON TM-T88III) """ p = Usb(0x04b8, 0x0202, 0, profile="TM-T88III") p.text("Hello World\n") p.image("logo.gif") p.barcode('4006381333931', 'EAN13', 64, 2, '', '') p.cut() ``` -------------------------------- ### Enable tab-completion for python-escpos CLI Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/installation.rst This command enables tab-completion for the python-escpos command-line interface using argcomplete. Ensure argcomplete is installed. ```bash eval "$(register-python-argcomplete python-escpos)" ``` -------------------------------- ### Serial Printer Basic Usage with QR Code Source: https://github.com/python-escpos/python-escpos/blob/master/README.rst Example for printing text, a QR code, and cutting paper using a serial printer. Requires specifying the serial device file and connection parameters, along with a profile. ```python from escpos.printer import Serial """ 9600 Baud, 8N1, Flow Control Enabled """ p = Serial( devfile='/dev/tty.usbserial', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=1.00, dsrdtr=True, profile="TM-T88III" ) p.text("Hello World\n") p.qr("You can readme from your smartphone") p.cut() ``` -------------------------------- ### Network Printer Basic Usage Source: https://github.com/python-escpos/python-escpos/blob/master/README.rst Example for printing text and barcodes to a network-connected printer. Requires the printer's IP address and a profile. ```python from escpos.printer import Network kitchen = Network("192.168.1.100", profile="TM-T88III") #Printer IP Address kitchen.text("Hello World\n") kitchen.barcode('4006381333931', 'EAN13', 64, 2, '', '') kitchen.cut() ``` -------------------------------- ### Send text to a network printer using netcat Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/printers.rst This command-line example demonstrates how to send raw text to a network-attached printer using netcat. Ensure the printer has a proper IP address and is listening on the specified port (commonly 9100). ```bash echo "OK\n" | nc IPADDRESS 9100 ``` -------------------------------- ### Full Printer Initialization and Operations Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Demonstrates initializing a specific USB printer model and performing common operations like printing text, images, QR codes, barcodes, and cutting the paper. ```python from escpos import * """ Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """ p = printer.Usb(0x04b8,0x0202, profile="TM-T88IV") # Print text p.text("Hello World\n") # Print image p.image("logo.gif") # Print QR Code p.qr("You can readme from your smartphone") # Print barcode p.barcode('4006381333931','EAN13',64,2,'','') # Cut paper p.cut() ``` -------------------------------- ### Full Printer Instance Initialization and Usage Source: https://github.com/python-escpos/python-escpos/wiki/Usage Demonstrates initializing an Epson TM-TI88IV USB printer and performing basic operations like printing text, images, QR codes, barcodes, and cutting the paper. ```python from escpos import * """ Seiko Epson Corp. Receipt Printer M129 Definitions (EPSON TM-T88IV) """ Epson = printer.Usb(0x04b8,0x0202) # Print text Epson.text("Hello World\n") # Print image Epson.image("logo.gif") # Print QR Code Epson.qr("You can readme from your smartphone") # Print barcode Epson.barcode('1324354657687','EAN13',64,2,'','') # Cut paper Epson.cut() ``` -------------------------------- ### Command-line Usage with Packaged Capabilities Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Demonstrates how to use the python-escpos command-line tool with its packaged capabilities profile. ```bash python-escpos cut ``` -------------------------------- ### Initialize USB Printer (Specific) Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Initialize a USB printer instance using its Vendor ID and Product ID. Default interface and output endpoint are used. ```python p = printer.Usb(0x04b8,0x0202) ``` -------------------------------- ### Initialize USB Printer (Epson) Source: https://github.com/python-escpos/python-escpos/wiki/Usage Initialize an Epson USB printer using its Vendor ID and Product ID. Default interface and output endpoint are used. ```python Epson = printer.Usb(0x04b8,0x0202) ``` -------------------------------- ### Build and Run Docker Image Source: https://github.com/python-escpos/python-escpos/blob/master/examples/docker-flask/README.md Builds a Docker image for the escpos-web application and then runs it, exposing port 9999. ```bash docker build . -t escpos-web docker run --network=host -p 9999:9999 escpos ``` -------------------------------- ### Command-line Usage with Custom Capabilities Path Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Shows how to specify a custom path for the capabilities profile using the ESCPOS_CAPABILITIES_FILE environment variable. ```bash export ESCPOS_CAPABILITIES_FILE=/usr/python-escpos/capabilities.json python-escpos cut ``` -------------------------------- ### Initialize Generic USB Printer Source: https://github.com/python-escpos/python-escpos/wiki/Usage Initialize a generic USB printer with custom interface and output endpoint addresses. Requires Vendor ID, Product ID, Interface number, and Output Endpoint address. ```python Generic = printer.Usb(0x1a2b,0x1a2b,0,0x81,0x02) ``` -------------------------------- ### Initialize and Update Git Submodules Source: https://github.com/python-escpos/python-escpos/blob/master/doc/dev/repository.rst Ensures all sub-projects are properly checked out and initialized. Run this command to maintain a complete Git project. ```bash git submodule update --init --recursive ``` -------------------------------- ### Initialize File Printer Source: https://github.com/python-escpos/python-escpos/wiki/Usage Initialize a printer using a file path, typically for devices like /dev/usb/lp1. The default is /dev/usb/lp0. ```python Epson = printer.File("/dev/usb/lp1") ``` -------------------------------- ### Image Preprocessing with Dummy Printer Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst This snippet demonstrates how to use the Dummy printer to preprocess print jobs, such as images, before sending them to the actual printer. This can help reduce perceived waiting times. ```Python from escpos.printer import Serial, Dummy p = Serial() d = Dummy() # create ESC/POS for the print job, this should go really fast d.text("This is my image:\n") d.image("funny_cat.png") d.cut() # send code to printer p._raw(d.output) ``` -------------------------------- ### Initialize Serial Printer Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Initialize a serial printer instance by specifying the serial port. Supports both Linux and Windows paths. ```python p = printer.Serial("/dev/tty0") ``` ```python p = printer.Serial("COM1") ``` -------------------------------- ### Load Configuration Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Load the configuration for python-escpos. If the configuration file is not found in the default location, it will indicate where it is looking. A path or list of paths can be provided to the load() method. ```python from escpos import config c = config.Config() c.load() ``` -------------------------------- ### Initialize Network Printer Source: https://github.com/python-escpos/python-escpos/wiki/Usage Initialize a network printer by providing its IP address. Assumes default port settings. ```python Epson = printer.Network("192.168.1.99") ``` -------------------------------- ### List USB Devices Source: https://github.com/python-escpos/python-escpos/wiki/Installation Use the `lsusb` command to find the Product ID and Vendor ID of your printer. These IDs are necessary for creating the udev rule. ```bash # lsusb Bus 002 Device 001: ID 1a2b:1a2b Device name ``` -------------------------------- ### set Source: https://github.com/python-escpos/python-escpos/wiki/Methods Configures text properties such as alignment, font, style (bold, underline), and size. ```APIDOC ## set ### Description Set text properties. ### Parameters #### Path Parameters - **align** (string) - Optional - Set horizontal position for text, the possible values are: CENTER, LEFT, RIGHT. Default: LEFT. - **font** (string) - Optional - Font type could be `A` or `B`. Default: A. - **type** (string) - Optional - Type could be `B` (Bold), `U` (Underline) or `normal`. Default: normal. - **width** (numeric) - Optional - A numeric value, 1 is for regular size, and 2 is twice the standard size. Default: 1. - **height** (numeric) - Optional - A numeric value, 1 is for regular size and 2 is twice the standard size. Default: 1. ``` -------------------------------- ### Command-line Usage Resetting Capabilities Path Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Illustrates how to unset the custom capabilities path to revert to using the packaged profile. ```bash unset ESCPOS_CAPABILITIES_FILE python-escpos cut ``` -------------------------------- ### Initialize Serial Printer Source: https://github.com/python-escpos/python-escpos/wiki/Usage Initialize a serial printer by specifying the serial port device. Default serial communication settings are used. ```python Epson = printer.Serial("/dev/tty0") ``` -------------------------------- ### Create Udev Rule for Printer Access Source: https://github.com/python-escpos/python-escpos/wiki/Installation Create a udev rule to grant users in the 'dialout' group access to the printer. Replace `1a2b` with your printer's actual Vendor and Product IDs. ```bash SUBSYSTEM=="usb", ATTRS{idVendor}=="1a2b", ATTRS{idProduct}=="1a2b", MODE="0664", GROUP="dialout" ``` -------------------------------- ### qr Source: https://github.com/python-escpos/python-escpos/wiki/Methods Prints a QR code with text encoded. The size is adjusted to Version 4 for optimal readability. ```APIDOC ## qr ### Description Prints a QR code. The size has been adjuested to Version 4, so it can be enough small to be printed but also enough big to be read by a smart phone. ### Parameters #### Path Parameters - **text** (string) - Required - Any text that needs to be QR encoded. It could be a slogan, salutation, url, etc. ``` -------------------------------- ### Set ESCPOS_CAPABILITIES_FILE Environment Variable Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst If the capabilities profile is not found due to packaging changes (e.g., with cx_freeze), set the `ESCPOS_CAPABILITIES_FILE` environment variable to the correct path of the JSON capabilities file. ```shell export ESCPOS_CAPABILITIES_FILE=/path/to/your/capabilities.json ``` -------------------------------- ### Print Raw Binary ESC/POS Commands Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Print raw binary data from a file containing ESC/POS commands using the `_raw()` method. This is useful for testing printer capabilities or reproducing issues with known command sequences. ```python from escpos import printer p = printer.Serial() # adapt this to your printer model file = open("binary-blob.bin", "rb") # read in the file containing your commands in binary-mode data = file.read() file.close() p._raw(data) ``` -------------------------------- ### escpos.printer.Dummy Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/printers.rst The Dummy printer class is designed for testing and debugging purposes. It captures all 'output' as raw ESC/POS commands in a string, which can be inspected. ```APIDOC ## escpos.printer.Dummy ### Description A dummy printer for testing and debugging. ### Usage Captures all output as raw ESC/POS commands in a string for inspection. ### Members (See source for detailed member information) ``` -------------------------------- ### Update Old USB Printer Code Source: https://github.com/python-escpos/python-escpos/wiki/Usage Shows the migration from an older USB printer initialization method to the current one, where the interface number is no longer required. ```python Epson = escpos.Escpos(0x04b8,0x0202,0) ``` ```python Epson = printer.Usb(0x04b8,0x0202) ``` -------------------------------- ### hw Source: https://github.com/python-escpos/python-escpos/wiki/Methods Executes hardware-specific operations on the printer. ```APIDOC ## hw ### Description Hardware operations. ### Parameters #### Path Parameters - **operation** (string) - Required - Is any of the following options: INIT, SELECT, RESET. ``` -------------------------------- ### escpos.printer.LP Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/printers.rst The LP printer class utilizes the UNIX 'lp' command to communicate with CUPS servers, supporting local and remote printers. The printer must be configured in CUPS. This driver spawns a subprocess to execute the 'lp' command. ```APIDOC ## escpos.printer.LP ### Description Implements printing via the UNIX 'lp' command to CUPS servers. ### Usage Requires the printer to be configured in CUPS. Spawns a subprocess to execute the 'lp' command. No external dependencies are required beyond the 'lp' command itself. ### Members (See source for detailed member information) ``` -------------------------------- ### Restart Udev Service Source: https://github.com/python-escpos/python-escpos/wiki/Installation Restart the udev service to apply the new rules. The command may vary depending on your system's version. ```bash # sudo service udev restart ``` ```bash # sudo udevadm control --reload ``` -------------------------------- ### image Source: https://github.com/python-escpos/python-escpos/wiki/Methods Prints an image by adjusting its size to fit the printer. Supports various image formats like jpg, gif, png, and bmp. ```APIDOC ## image ### Description Prints an image. Its adjust the size in order to print it. ### Parameters #### Path Parameters - **image_name.ext** (string) - Required - The complete file name and location of any image type (jpg, gif, png, bmp). ### Exceptions - `ImageSizeError` ``` -------------------------------- ### escpos.printer.File Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/printers.rst The File printer class directs output to a file handle, which is particularly useful on Unix-like systems. This allows for capturing print output to a file for later processing or inspection. ```APIDOC ## escpos.printer.File ### Description Redirects printer output to a file handle. ### Usage Convenient for capturing print data, especially on Unix-like systems. ### Members (See source for detailed member information) ``` -------------------------------- ### escpos.printer.Win32Raw Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/printers.rst The Win32Raw printer class uses a native Windows WIN32 interface for printing. Documentation for this driver is not included in the build and is available in the source code. ```APIDOC ## escpos.printer.Win32Raw ### Description Implements printing using the native WIN32 interface on Windows. ### Usage Directly interfaces with Windows printing mechanisms. ### Documentation Refer to the source code for detailed documentation as it is not included in the build. ``` -------------------------------- ### text Source: https://github.com/python-escpos/python-escpos/wiki/Methods Prints raw text to the printer. Handles basic text output. ```APIDOC ## text ### Description Prints raw text. ### Parameters #### Path Parameters - **text** (string) - Required - The raw text to print. ### Exceptions - `TextError` ``` -------------------------------- ### escpos.printer.CupsPrinter Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/printers.rst The CupsPrinter class communicates with a CUPS server using pycups, supporting both local and remote printers. The printer must be configured in CUPS, and the driver generates a print job for the CUPS queue. ```APIDOC ## escpos.printer.CupsPrinter ### Description Implements communication with CUPS servers for printing. ### Usage Requires the printer to be configured in CUPS. Generates a print job that is added to the CUPS queue. Supports local and remote CUPS printers and servers. ### Members (See source for detailed member information) ``` -------------------------------- ### Print Text with Unicode Support Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Pass Unicode text directly to the `text()` function for automatic code page detection and encoding. If this fails, consider manually setting the code page using `charcode()` or reporting an issue. ```python from escpos import printer p = printer.Usb() p.text('Hello, World!\n') p.text('This is a Unicode string: \u20ac\n') ``` -------------------------------- ### Print CODE128 Barcode Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/barcode.rst This snippet demonstrates how to print a CODE128 barcode using the `barcode` method. Ensure the payload is correctly formatted, prefacing alphanumeric data with `{B`. ```Python from escpos.printer import Dummy, Serial p = Serial() # print CODE128 012ABCDabcd p.barcode("{B012ABCDabcd", "CODE128", function_type="B") ``` -------------------------------- ### cashdraw Source: https://github.com/python-escpos/python-escpos/wiki/Methods Sends a pulse to the cash drawer connected to a specified pin. ```APIDOC ## cashdraw ### Description Sends a pulse to the cash drawer in the specified pin. ### Parameters #### Path Parameters - **pin** (numeric) - Required - A numeric value which defines the pin to be used to send the pulse, it could be 2 or 5. ### Exceptions - `CashDrawerError` ``` -------------------------------- ### Set Sleep Time Between Image Fragments Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst To resolve 'USBTimeoutError' during image printing, use `set_sleep_in_fragment()` to introduce a delay between sending data fragments. Adjust the sleep duration as needed. ```python from escpos import printer p = printer.Usb() p.set_sleep_in_fragment(0.1) # Set sleep time to 0.1 seconds # ... proceed with image printing ... ``` -------------------------------- ### barcode Source: https://github.com/python-escpos/python-escpos/wiki/Methods Prints a barcode with specified type, dimensions, and positioning. Supports various barcode types and customizable appearance. ```APIDOC ## barcode ### Description Prints a barcode. ### Parameters #### Path Parameters - **code** (string) - Required - An alphanumeric code to be printed as bar code. - **barcode_type** (string) - Required - Must be one of the following type of codes: UPC-A, UPC-E, EAN13, EAN8, CODE39, ITF, NW7. - **width** (numeric) - Optional - A numeric value in the range between (1,255). Default: 64. - **height** (numeric) - Optional - A numeric value in the range between (2,6). Default: 3. - **position** (string) - Optional - Where to place the code around the bars, could be one of the following values: ABOVE, BELOW, BOTH, OFF. Default: BELOW. - **font** (string) - Optional - One of the 2 type of fonts, values could be: A, B. Default: A. ### Exceptions - `BarcodeTypeError` - `BarcodeSizeError` - `BarcodeCodeError` ``` -------------------------------- ### Manually Set Code Page Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/usage.rst Use the `charcode()` function to manually set the printer's code page. This overrides automatic detection. Use `CHARCODE.AUTO` to revert to automatic behavior. An invalid code page will raise `CharCodeError`. ```python from escpos import printer, CHARCODE p = printer.Usb() p.charcode(CHARCODE.CODEPAGE_437) # Example: Set to Code Page 437 p.text('Some text') p.charcode(CHARCODE.AUTO) # Revert to automatic ``` -------------------------------- ### control Source: https://github.com/python-escpos/python-escpos/wiki/Methods Manages carrier feed and tab operations for printer control. ```APIDOC ## control ### Description Carrier feed and tabs. ### Parameters #### Path Parameters - **align** (string) - Required - Is a string which takes any of the following values: LF (Line Feed), FF (Form Feed), CR (Carriage Return), HT (Horizontal Tab), VT (Vertical Tab). ``` -------------------------------- ### escpos.printer.Serial Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/printers.rst The Serial printer class utilizes pyserial for communication with serial devices. This driver is suitable for both direct serial connections and USB-to-Serial adapters. Hardware configuration details should be obtained from the printer's manual. ```APIDOC ## escpos.printer.Serial ### Description Implements communication with serial printers using pyserial. ### Usage Suitable for direct serial connections and USB-to-Serial adapters. Refer to the printer's manual for hardware configuration. ### Members (See source for detailed member information) ``` -------------------------------- ### escpos.printer.Usb Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/printers.rst The Usb printer class uses pyusb and libusb to communicate with USB-based printers. It is specifically designed for native USB devices and not for USB-to-Serial adapters. ```APIDOC ## escpos.printer.Usb ### Description Implements communication with USB printers using pyusb and libusb. ### Usage This class is intended for printers that implement native USB communication. ### Members (See source for detailed member information) ``` -------------------------------- ### cut Source: https://github.com/python-escpos/python-escpos/wiki/Methods Performs a paper cut operation, either full or partial. Note that partial cuts may not be supported by all printers. ```APIDOC ## cut ### Description Cut paper. ### Parameters #### Path Parameters - **mode** (string) - Optional - Set a full or partial cut. Default: full. > Partial cut is not implemented in all printers. ``` -------------------------------- ### escpos.printer.Network Source: https://github.com/python-escpos/python-escpos/blob/master/doc/user/printers.rst The Network printer class is based on the socket class for network communication. It allows printing to network-attached printers. Troubleshooting network issues may involve checking IP addresses and sending manual test data. ```APIDOC ## escpos.printer.Network ### Description Implements network communication with printers using sockets. ### Usage Connects to network-attached printers. Ensure the device has a proper IP address and the correct port (often 9100) is used. ### Troubleshooting - Verify IP address and network connectivity. - Test sending data manually using tools like `nc`. - Reset the printer's network interface if necessary. ### Members (See source for detailed member information) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.