recibo

Crates.iorecibo
lib.rsrecibo
version0.3.0
sourcesrc
created_at2023-06-04 10:34:10.579254
updated_at2023-06-05 23:10:50.746795
descriptionESC/POS printer driver for Rust
homepagehttps://github.com/jamhall/recibo
repositoryhttps://github.com/jamhall/recibo
max_upload_size
id882096
size364,702
Jamie Hall (jamhall)

documentation

README

recibo - ESC/POS driver for Rust Build Status Latest Version

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 print out

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.
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

Commit count: 8

cargo fmt