| Crates.io | brother_ql |
| lib.rs | brother_ql |
| version | 2.2.0 |
| created_at | 2024-03-07 20:30:32.803445+00 |
| updated_at | 2025-12-15 19:03:40.287343+00 |
| description | Compile and print images using Brother QL label printers |
| homepage | |
| repository | https://github.com/mkienitz/brother_ql |
| max_upload_size | |
| id | 1166266 |
| size | 218,090 |
This is a crate to convert image data to the Raster Command binary data understood by Brother QL series label printers.
Looking for a CLI tool? Check out brother-label, a command-line application built on this library.
See the list of supported printers in the main README.
Note: This crate is still work-in-progress and some bugs might still exist.
For more details, check the official Raster Command Reference (this one is for the 8xx series).
cargo add brother_ql
# Or with optional features:
cargo add brother_ql --features usb
Feature flags:
usb - Enable USB printing support (requires libusb)serde - Enable serialization supportNote: Requires the usb feature.
use brother_ql::{
connection::{PrinterConnection, UsbConnection, UsbConnectionInfo},
media::Media, printer::PrinterModel, printjob::PrintJob,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create connection info for QL-820NWB
let info = UsbConnectionInfo::from_model(PrinterModel::QL820NWB);
// Open USB connection
let mut connection = UsbConnection::open(info)?;
// Read status from printer
let _status = connection.get_status()?;
// Create a print job with more than one page
let img = image::open("c62.png")?;
let job = PrintJob::new(img, Media::C62)?.page_count(2);
// These are the defaults for the other options:
// .high_dpi(false)
// .compressed(false)
// .quality_priority(true)
// .cut_behavior(CutBehavior::CutEach)?; // default for continuous media
// Finally, print
connection.print(job)?;
Ok(())
}
Note: Works without any optional features. On Linux, you can use the kernel's USB printer driver (/dev/usb/lp0).
use brother_ql::{
connection::{KernelConnection, PrinterConnection},
media::Media, printjob::PrintJob,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open kernel device connection
let mut connection = KernelConnection::open("/dev/usb/lp0")?;
// Create and print a job
let img = image::open("c62.png")?;
let job = PrintJob::new(img, Media::C62)?;
connection.print(job)?;
Ok(())
}
Note: Works without any optional features.
use std::{fs::File, io::Write};
use brother_ql::{media::Media, printjob::PrintJob};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let img = image::open("c62.png")?;
let job = PrintJob::new(img, Media::C62)?;
let data = job.compile();
let mut file = File::create("c62mm.bin")?;
file.write_all(&data)?;
Ok(())
}