recibo - ESC/POS driver for Rust

This project provides an implementation for a subset of Epson's ESC/POS protocol tailored specifically for receipt printers. It can generate and print receipts that include basic formatting, barcodes, graphics and cutting functions on a compatible printer.

Example print out -

Example usage

```rust let driver = NetworkDriver::open("127.0.0.1", 9100)?; let mut printer = Printer::open(driver)?;

printer.init()? .align(Alignment::Center)? .text_size(4, 4)? .text("Hello World")? .feed(2)? .graphic(move |builder| { builder.path("resources/rust-logo.png") .size(GraphicSize::Normal) })? .feed(4)? .cut()?; ```

Table of Contents

Examples

Refer to the examples directory for further instances of usage.

For the sake of simplicity, the examples will print their output to the console.

To launch an example, use the following command:

shell cargo run --example graphic --features "graphics" --quiet

If you wish to direct an example's output to a network printer, you can employ the netcat command:

shell cargo run --example text | nc 192.168.0.100 9100

Installation

For standard functionalities (e.g. printing text, barcodes, qr codes etc.), no additional dependencies are required:

[dependencies] recibo = "1.0.0"

If you would like to raster images, you will need to enable the image feature:

[dependencies] recibo = { version = "1.0.0", features = ["graphics"] }

Adapters

The library provides two adapters for communicating with the printer:

NetworkDriver

This is used for establishing communication with a network printer

shell let driver = NetworkDriver::open("192.168.0.100", 9100)?; let printer = Printer::open(driver)?;

FileDriver

This is used when interacting with a serial printer or writing to a file

shell let driver = FileDriver::open("/tmp/output.bin")?; let printer = Printer::open(driver)?;

ConsoleDriver

This is used for writing the output to the console

shell let driver = ConsoleDriver::open(); let printer = Printer::open(driver)?;

Supported Commands

Some of the commands may not be supported by your printer

| Command | Description | |-------------------|--------------------------------------------------------------------| | init | Initializes the printer. | | reset | Resets the printer to its default settings. | | align | Aligns the text to the left, right, or center. | | left | Sets the left margin to n dots. | | width | Sets the printable area width. | | font | Sets the font to either style 'a', 'b', or 'c'. | | bold | Sets the emphasis of the text to bold. | | textsize | Sets the font size of the text. | | resettextsize | Resets the font size of the text. | | underline | Underlines the text with a single or double stroke. | | doublestrike | Applies a double-strike effect to the text. | | linespacing | Adjusts the spacing between lines of text. | | resetlinespacing | Resets the line spacing to the default value. | | flip | Turns the text upside down. | | reversecolours | Enables white text on a black background. | | qr | Prints a QR Code. | | barcode | Prints a barcode. | | graphic | Prints a graphic. | | feed | Feeds n lines of paper. | | reversefeed | Reverses the paper feed by n lines. | | cut | Performs a full cut of the paper. | | partial_cut | Performs a partial cut of the paper. | | print | Prints the specified text. | | println | Prints the specified text with a new line ending. | | text | Same as println, prints the specified text with a new line ending. |

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details