local-group / rust-escposify

A ESC/POS driver in Rust ( Documentation: https://docs.rs/escposify )
MIT License
52 stars 18 forks source link

windows 10 how to? #10

Open stonewjr opened 2 years ago

stonewjr commented 2 years ago

run in windows10 copy testfile "\\LAPTOP-QV366NUQ\Receipt Printer" ok but run examples\simple.rs no error and printer not things happened? no error and no message ...

mdennyh commented 2 years ago

The author clearly doesn't provide a working sample to a printer. so here's one:

extern crate escposify;
extern crate tempfile;
use std::fs;
use std::io;

use escposify::device::File;
use escposify::printer::Printer;

fn main() -> io::Result<()> {

    // after you shares your printer, use the following code
    // the IP is the your computer's IP address
    // "Receipt Printer" is the shared name of your printer 
    // (check the control panel -> devices and printer)
    let path = "//192.168.100.8/Receipt Printer";

    // create a file and send it to the printer's path
    // if the path is not available/error you should handle it here.
    let file = File::<fs::File>::from_path(path)?;

    // prepare the variable
    let mut printer = Printer::new(file, None, None);

    printer
        .chain_font("C")?
        .chain_align("lt")?
        .chain_style("bu")?
        .chain_size(0, 0)?
        .chain_text("The quick brown fox jumps over the lazy dog")?
        .chain_text("敏捷的棕色狐狸跳过懒狗")?
        .chain_barcode("12345678", "EAN8", "", "", 0, 0)?
        .chain_feed(1)?
        .chain_cut(false)?
        .flush()
}
yooouuri commented 1 year ago

@mdennyh how to do the same for a USB printer for Mac OS?

mdennyh commented 1 year ago

I haven't try to use it in MacOS. But I believe it should be the same. This depends on escposify::device::File; which is a wrapper for std::fs::File. As long as your printer can receive a text file as direct input it should be fine.

But the problem with Apple devices is that it might not be that simple. Apple use bonjour as its print service (https://www.macworld.com/article/189499/macwinprint.html). If you can manage to print from windows to printer on the MacOS, then you can use this package too using the same printer URI