|
|
|
@ -96,30 +96,42 @@ fn get_printer_capabilities(device_name: String) -> HashMap<String, Vec<String>> |
|
|
|
#[tauri::command] |
|
|
|
#[tauri::command] |
|
|
|
fn print_document(device_name: String, document_path: String, dpi: String, color: String, size: String) { |
|
|
|
fn print_document(device_name: String, document_path: String, dpi: String, color: String, size: String) { |
|
|
|
println!("Printing document: {}, {}, {}, {}", document_path, size, dpi, color); |
|
|
|
println!("Printing document: {}, {}, {}, {}", document_path, size, dpi, color); |
|
|
|
let my_device = match get_my_device(device_name) { |
|
|
|
let my_device = match get_my_device(device_name.clone()) { |
|
|
|
Some(device) => device, |
|
|
|
Some(device) => device, |
|
|
|
None => { |
|
|
|
None => { |
|
|
|
println!("My Printer not found."); |
|
|
|
println!("Printer not found: {}", device_name); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
println!("My Printer: {:?}", my_device.name()); |
|
|
|
// println!("My Printer: {:?}", my_device.name());
|
|
|
|
|
|
|
|
|
|
|
|
let capabilities = PrintCapabilities::fetch(&my_device).unwrap(); |
|
|
|
let capabilities = PrintCapabilities::fetch(&my_device).unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let parsed_size = size.parse::<PredefinedMediaName>() |
|
|
|
|
|
|
|
.expect("Invalid media size name"); |
|
|
|
|
|
|
|
|
|
|
|
let a6_media = capabilities |
|
|
|
let a6_media = capabilities |
|
|
|
.page_media_sizes() |
|
|
|
.page_media_sizes() |
|
|
|
.find(|x| format!("{:?}", x.as_predefined_name()) == size) |
|
|
|
.find(|x| x.as_predefined_name() == Some(parsed_size)) |
|
|
|
.unwrap(); |
|
|
|
.expect("Media size not supported by printer"); |
|
|
|
|
|
|
|
|
|
|
|
let mut builder = PrintTicketBuilder::new(&my_device).unwrap(); |
|
|
|
let mut builder = PrintTicketBuilder::new(&my_device).unwrap(); |
|
|
|
builder.merge(a6_media).unwrap(); |
|
|
|
builder.merge(a6_media).unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
let ticket = builder.build().unwrap(); |
|
|
|
let ticket = builder.build().unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
// let theprinter = PdfiumPrinter::new(my_device);
|
|
|
|
|
|
|
|
let theprinter = ImagePrinter::new(my_device); |
|
|
|
|
|
|
|
let path = Path::new(&document_path); |
|
|
|
let path = Path::new(&document_path); |
|
|
|
theprinter.print(path, ticket).unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
if path.extension().map(|ext| ext.eq_ignore_ascii_case("pdf")).unwrap_or(false) { |
|
|
|
|
|
|
|
let printer=PdfiumPrinter::new(my_device); |
|
|
|
|
|
|
|
printer.print(path, ticket).unwrap(); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
let printer=ImagePrinter::new(my_device); |
|
|
|
|
|
|
|
printer.print(path, ticket).unwrap(); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
// let theprinter = PdfiumPrinter::new(my_device);
|
|
|
|
|
|
|
|
// let theprinter = ImagePrinter::new(my_device);
|
|
|
|
|
|
|
|
// theprinter.print(path, ticket).unwrap();
|
|
|
|
} |
|
|
|
} |
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)] |
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)] |
|
|
|
pub fn run() { |
|
|
|
pub fn run() { |
|
|
|
|