brother_ql 3.0.1

Compile and print images using Brother QL label printers
Documentation
# brother_ql

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](https://crates.io/crates/brother-label), a command-line application built on this library.

## Features

- **📦 Compile to binary data** - Convert images to raster command bytes that can be sent to the printer via USB, network, or saved to files
- **🔌 Direct USB printing** - Print labels directly via USB connection with full status monitoring (also supported via a kernel connection)
- **📊 Status information** - Read detailed printer status including errors, media type, and operational phase
- **🎨 Two-color printing** - Support for red and black printing on compatible printer models
- **🏷️ Multiple media types** - Support for continuous and die-cut labels in various widths

## Supported Printers

See the [list of supported printers](https://github.com/mkienitz/brother_ql?tab=readme-ov-file#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](https://download.brother.com/welcome/docp100278/cv_ql800_eng_raster_101.pdf) (this one is for the 8xx series).

## Installation

```bash
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 support

## Examples

### Printing via USB connection

**Note:** Requires the `usb` feature.

```rust
use brother_ql::{
    connection::{PrinterConnection, UsbConnection, UsbConnectionInfo},
    media::Media, printer::PrinterModel, printjob::PrintJobBuilder,
};

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
    let img = image::open("c62.png")?;
    let job = PrintJobBuilder::new(Media::C62)
        .add_label(img)
        // These are the defaults for the other options:
        // .high_dpi(false)
        // .compressed(false)
        // .quality_priority(true)
        // .cut_behavior(CutBehavior::CutEach) // default for continuous media
        .build()?;
    // Finally, print
    connection.print(job)?;
    Ok(())
}
```

### Printing via kernel connection

**Note:** Works without any optional features. On Linux, you can use the kernel's USB printer driver (`/dev/usb/lp0`).

```rust
use brother_ql::{
    connection::{KernelConnection, PrinterConnection},
    media::Media, printjob::PrintJobBuilder,
};

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 = PrintJobBuilder::new(Media::C62)
        .add_label(img)
        .build()?;
    connection.print(job)?;
    Ok(())
}
```

### Compiling and saving a print job

**Note:** Works without any optional features.

```rust
use std::{fs::File, io::Write};
use brother_ql::{media::Media, printjob::PrintJobBuilder};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let img = image::open("c62.png")?;
    let job = PrintJobBuilder::new(Media::C62)
        .add_label(img)
        .build()?;
    let data = job.compile();
    let mut file = File::create("c62mm.bin")?;
    file.write_all(&data)?;
    Ok(())
}
```