Derafu: ESCPOS - PHP Library for ESC/POS Printers
A PHP library for generating ESC/POS commands to communicate with thermal receipt printers. This library is a wrapper around Mike42/escpos-php that provides a more fluent interface and additional features.
Features
- Simplified API for common receipt printing tasks.
- Support for multiple connector types.
- Text formatting (alignment, font styles, etc.).
- 1D and 2D barcode generation (including PDF417).
- Special character handling and replacement.
- Receipt cutting and cash drawer opening.
- Chainable methods for cleaner code.
Installation
You can install the package via composer:
Usage
Basic Example
Full Example
The example show how to use all the features.
Run the example with:
Note: You need netcat
installed in your system, and 172.16.1.5
9100
are the IP and port of your thermal printer.
Configuration Options
The EscposPrinter
class accepts the following configuration options:
Option | Type | Default | Description |
---|---|---|---|
connector | array | ['type' => 'dummy'] |
Printer connector configuration |
profile | string | 'default' |
Printer capability profile |
cut | bool | true |
Automatically cut paper at the end |
specialchars | bool | true |
Replace special characters (like accents) |
pulse | array | ['pin' => 0, 'on_ms' => 120, 'off_ms' => 240] |
Cash drawer opening configuration |
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
License
This package is open-sourced software licensed under the MIT license.