3 releases (breaking)
0.3.0 | Jun 5, 2023 |
---|---|
0.2.0 | Jun 5, 2023 |
0.1.0 | Jun 4, 2023 |
#260 in Graphics APIs
300KB
2K
SLoC
recibo - ESC/POS driver for Rust
This project provides an implementation for a subset of Epson's ESC/POS protocol used by compatible receipt printers. It can generate and print receipts that include basic formatting, barcodes, graphics and cutting functions on a compatible printer.
Example usage
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:
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:
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"] }
You can also enable deserialisation and serialisation using serde if you enable the feature:
[dependencies]
recibo = { version = "1.0.0", features = ["serde"] }
Adapters
The library provides two adapters for communicating with the printer:
NetworkDriver
This is used for establishing communication with a network printer
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
let driver = FileDriver::open("/tmp/output.bin")?;
let printer = Printer::open(driver)?;
ConsoleDriver
This is used for writing the output to the console
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. |
text_size | Sets the font size of the text. |
reset_text_size | 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. |
reset_linespacing | Resets the line spacing to the default value. |
flip | Turns the text upside down. |
reverse_colours | 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. |
reverse_feed | Reverses the paper feed by n lines. |
cut | Performs a full cut of the paper. |
partial_cut | Performs a partial cut of the paper. |
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
Dependencies
~2.4–3.5MB
~52K SLoC