xhs_electronic_print/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
mod declare;
use log::{info, error};
#[cfg(target_os = "windows")]
mod windows;

#[cfg(target_os = "macos")]
mod macos;

pub fn print(id: String, path: String, printer_setting: String, remove_after_print: bool) -> String {
    info!("main print_pdf");
    
    let options = declare::PrintOptions {
        id: id.clone(),
        path: path.clone(),
        print_setting: printer_setting.clone(),
        remove_after_print,
    };
    #[cfg(target_os = "windows")]
    match windows::print(options) {
        Ok(_) => "Windows-打印成功".to_string(),
        Err(err) => format!("Windows-打印失败: {}", err),
    };

    #[cfg(target_os = "macos")]
    match macos::print(id.clone(), path.clone(), printer_setting.clone(), remove_after_print) {
        Ok(_) => "MacOS-打印成功".to_string(),
        Err(err) => format!("MacOS-打印失败: {}", err),
    }

}