simple/
simple.rs

1use anyhow::Result;
2use tspl2::{Alignment, Barcode, Font, HumanReadable, NarrowWide, Printer, Rotation, Size, Tape};
3
4fn main() -> Result<()> {
5    // Get access to the printer
6    std::process::Command::new("sudo")
7        .args(["chmod", "777", "/dev/usb/lp0"])
8        .output()?;
9
10    let tape = Tape {
11        width: Size::Metric(30.0),
12        height: Some(Size::Metric(20.0)),
13        gap: Size::Metric(2.0),
14        gap_offset: None,
15    };
16
17    let mut printer = Printer::with_resolution("/dev/usb/lp0", tape, 300)?;
18    printer
19        .cls()?
20        .qrcode(
21            Size::Metric(9.0),
22            Size::Metric(0.0),
23            35,
24            6,
25            Rotation::NoRotation,
26            None,
27            "0123456789AB",
28        )?
29        .text(
30            Size::Metric(15.0),
31            Size::Metric(14.5),
32            Font::Font24x32,
33            Rotation::NoRotation,
34            1,
35            1,
36            Some(Alignment::Center),
37            "0123456789AB",
38        )?
39        .print(1, None)?;
40
41    printer
42        .cls()?
43        .barcode(
44            Size::Metric(15.0),
45            Size::Metric(0.0),
46            Barcode::Barcode39,
47            Size::Metric(15.0),
48            HumanReadable::ReadableAlignsToCenter,
49            Rotation::NoRotation,
50            NarrowWide::N1W3,
51            Some(Alignment::Center),
52            "0123456789AB",
53        )?
54        .print(1, None)?;
55
56    Ok(())
57}