ESC/POS driver for Rust 🦀

Related tags

Command-line recibo
Overview

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

You might also like...
FTL Rust Demangler is a command-line tool for demangling symbol names that are mangled with the Rust convention

FTL Rust Demangler is a command-line tool for demangling symbol names that are mangled with the Rust convention. It takes a mangled symbol name as input and returns the demangled name

rpm (Rust project manager) is a tool that helps you to manage your rust projects

rpm rpm (Rust project manager) is a open source tool for managing your rust project in an organized way Installation # make sure you have rust install

auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, utilizing procedural macros.
auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, utilizing procedural macros.

Auto Rust auto-rust is an experimental project that aims to automatically generate Rust code with LLM (Large Language Models) during compilation, util

Rusty Shellcode Reflective DLL Injection (sRDI) - A small reflective loader in Rust 4KB in size for generating position-independent code (PIC) in Rust.
Rusty Shellcode Reflective DLL Injection (sRDI) - A small reflective loader in Rust 4KB in size for generating position-independent code (PIC) in Rust.

Shellcode Reflective DLL Injection (sRDI) Shellcode reflective DLL injection (sRDI) is a process injection technique that allows us to convert a given

This rust compiler backend emmits valid CLR IR, enambling you to use Rust in .NET projects

What is rustc_codegen_clr? NOTE: this project is a very early proof-of-concept This is a compiler backend for rustc which targets the .NET platform an

RustGPT is a ChatGPT UI built with Rust + HTMX: the power of Rust coupled with the simplicity of HTMX 💚

RustGPT 🦀✨ RustGPT.Blog.Post.mp4 Welcome to the RustGPT repository! Here, you'll find a web ChatGPT clone entirely crafted using Rust and HTMX, where

Rust API Server: A versatile template for building RESTful interfaces, designed for simplicity in setup and configuration using the Rust programming language.
Rust API Server: A versatile template for building RESTful interfaces, designed for simplicity in setup and configuration using the Rust programming language.

RUST API SERVER Introduction Welcome to the Rust API Server! This server provides a simple REST interface for your applications. This README will guid

A full featured, fast Command Line Argument Parser for Rust

clap Command Line Argument Parser for Rust It is a simple-to-use, efficient, and full-featured library for parsing command line arguments and subcomma

Docopt for Rust (command line argument parser).

THIS CRATE IS UNMAINTAINED This crate is unlikely to see significant future evolution. The primary reason to choose this crate for a new project is if

Releases(v0.3.0)
Owner
Jamie Hall
Jamie Hall
A Windows virtual display driver written in Rust (works with VR, etc)

Virtual Display Driver This is a Windows driver made in Rust which creates a virtual desktop. It has many uses, such as: A private virtual desktop for

Cherry 28 Sep 19, 2023
Platform that enables Windows driver development in Rust. Developed by Surface.

windows-drivers-rs This repo is a collection of Rust crates that enable developers to develop Windows Drivers in Rust. It is the intention to support

Microsoft 1.1k Oct 11, 2023
🚀 JavaScript driver for ScyllaDB, harnessing Rust's power through napi-rs for top performance. Pre-release stage. 🧪🔧

?? JavaScript driver for ScyllaDB. Pre-release stage. ???? ⚠️ Disclaimer ⚠️ This repository and the associated npm package are currently in a ?? pre-r

Daniel Boll 16 Oct 21, 2023
A filesystem driver that allows you to view your Blackboard course contents as if they were normal files and folders on your system!

BlackboardFS Blackboard: noun A website so bad that it might as well be a network drive. BlackboardFS is a filesystem driver that allows you to view y

null 22 Sep 4, 2023
auto-epp-rs is a program that manages the energy performance preferences (EPP) of your AMD CPU using the AMD-Pstate driver.

auto-epp-rs is a program that manages the energy performance preferences (EPP) of your AMD CPU using the AMD-Pstate driver. It adjusts the EPP settings based on whether your system is running on AC power or battery power, helping optimize power consumption and performance. This project is a rewrite of the original Python version jothi-prasath/auto-epp in Rust, aiming to improve memory efficiency and overall performance.

Taufik Hidayat 3 Nov 3, 2023
Rust-advent - Learning Rust by solving advent of code challenges (Streaming live on Twitch every Monday)

Rust advent ?? ?? Learning Rust by implementing solutions for Advent of Code problems. ?? HEY, we are live-streaming our attempts to solve the exercis

Luciano Mammino 20 Nov 11, 2022
Rust-clippy - A bunch of lints to catch common mistakes and improve your Rust code

Clippy A collection of lints to catch common mistakes and improve your Rust code. There are over 450 lints included in this crate! Lints are divided i

The Rust Programming Language 8.7k Dec 31, 2022
Rust-battery - Rust crate providing cross-platform information about the notebook batteries.

battery Rust crate providing cross-platform information about the notebook batteries. Table of contents Overview Supported platforms Install Examples

svartalf 326 Dec 21, 2022
A Rust-based shell script to create a folder structure to use for a single class every semester. Mostly an excuse to use Rust.

A Rust Course Folder Shell Script PROJECT IN PROGRESS (Spring 2022) When completed, script will create a folder structure of the following schema: [ro

Sebastián Romero Cruz 1 Apr 10, 2022
Rust Imaging Library's Python binding: A performant and high-level image processing library for Python written in Rust

ril-py Rust Imaging Library for Python: Python bindings for ril, a performant and high-level image processing library written in Rust. What's this? Th

Cryptex 13 Dec 6, 2022