|
|
|
@ -7,8 +7,8 @@ use winprint::ticket::{ |
|
|
|
PrintCapabilities, PrintTicket, PrintTicketBuilder, |
|
|
|
PrintCapabilities, PrintTicket, PrintTicketBuilder, |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
mod util; |
|
|
|
|
|
|
|
mod raw_convert; |
|
|
|
mod raw_convert; |
|
|
|
|
|
|
|
mod util; |
|
|
|
|
|
|
|
|
|
|
|
#[tauri::command] |
|
|
|
#[tauri::command] |
|
|
|
fn get_all_printers() -> Vec<String> { |
|
|
|
fn get_all_printers() -> Vec<String> { |
|
|
|
@ -31,8 +31,7 @@ fn convert_pdf(document_path: String) -> Result<String, String> { |
|
|
|
return Err(format!("File does not exist: {}", document_path)); |
|
|
|
return Err(format!("File does not exist: {}", document_path)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match raw_convert::imageToPdf2(document_path.clone()) { |
|
|
|
match raw_convert::imageToPdf2(document_path.clone()) { |
|
|
|
|
|
|
|
Ok(pdf_path) => { |
|
|
|
Ok(pdf_path) => { |
|
|
|
// Print the converted PDF using the printer
|
|
|
|
// Print the converted PDF using the printer
|
|
|
|
// printer.print(Path::new(&pdf_path), ticket).unwrap();
|
|
|
|
// printer.print(Path::new(&pdf_path), ticket).unwrap();
|
|
|
|
@ -56,7 +55,7 @@ fn get_printer_capabilities(device_name: String) -> HashMap<String, Vec<String>> |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
println!("My Printer: {:?}", my_device.name()); |
|
|
|
println!("My Printer: {:?}", my_device.name()); |
|
|
|
|
|
|
|
|
|
|
|
let mut map = HashMap::new(); |
|
|
|
let mut map = HashMap::new(); |
|
|
|
|
|
|
|
|
|
|
|
match PrintCapabilities::fetch_xml(&my_device) { |
|
|
|
match PrintCapabilities::fetch_xml(&my_device) { |
|
|
|
@ -68,7 +67,6 @@ fn get_printer_capabilities(device_name: String) -> HashMap<String, Vec<String>> |
|
|
|
println!("DPI Options: {:?}", quality_opts); |
|
|
|
println!("DPI Options: {:?}", quality_opts); |
|
|
|
|
|
|
|
|
|
|
|
map.insert("quality_options".to_string(), quality_opts); |
|
|
|
map.insert("quality_options".to_string(), quality_opts); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
|
println!("Failed to fetch capabilities: {:?}", e); |
|
|
|
println!("Failed to fetch capabilities: {:?}", e); |
|
|
|
@ -95,7 +93,6 @@ fn get_printer_capabilities(device_name: String) -> HashMap<String, Vec<String>> |
|
|
|
println!("Color Options: {:?}", color_opts_value); |
|
|
|
println!("Color Options: {:?}", color_opts_value); |
|
|
|
println!("Size Options: {:?}", size_opts_value); |
|
|
|
println!("Size Options: {:?}", size_opts_value); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map.insert("dpi_options".to_string(), dpi_opts_value); |
|
|
|
map.insert("dpi_options".to_string(), dpi_opts_value); |
|
|
|
map.insert("color_options".to_string(), color_opts_value); |
|
|
|
map.insert("color_options".to_string(), color_opts_value); |
|
|
|
map.insert("size_options".to_string(), size_opts_value); |
|
|
|
map.insert("size_options".to_string(), size_opts_value); |
|
|
|
@ -111,7 +108,8 @@ fn default_ticket(quality: Option<String>) -> PrintTicket { |
|
|
|
// let mut ticket = PrintTicket::new();
|
|
|
|
// let mut ticket = PrintTicket::new();
|
|
|
|
let _quality = quality.unwrap_or_else(|| "psk:Normal".to_string()); |
|
|
|
let _quality = quality.unwrap_or_else(|| "psk:Normal".to_string()); |
|
|
|
|
|
|
|
|
|
|
|
let xml =format!(r#"<?xml version="1.0" encoding="UTF-8"?> |
|
|
|
let xml = format!( |
|
|
|
|
|
|
|
r#"<?xml version="1.0" encoding="UTF-8"?> |
|
|
|
<psf:PrintTicket version="1" |
|
|
|
<psf:PrintTicket version="1" |
|
|
|
xmlns:psf="http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework" |
|
|
|
xmlns:psf="http://schemas.microsoft.com/windows/2003/08/printing/printschemaframework" |
|
|
|
xmlns:psk="http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords"> |
|
|
|
xmlns:psk="http://schemas.microsoft.com/windows/2003/08/printing/printschemakeywords"> |
|
|
|
@ -121,7 +119,8 @@ fn default_ticket(quality: Option<String>) -> PrintTicket { |
|
|
|
<psf:Feature name="psk:PageOutputQuality"> |
|
|
|
<psf:Feature name="psk:PageOutputQuality"> |
|
|
|
<psf:Option name="{_quality}" /> |
|
|
|
<psf:Option name="{_quality}" /> |
|
|
|
</psf:Feature> |
|
|
|
</psf:Feature> |
|
|
|
</psf:PrintTicket>"#); |
|
|
|
</psf:PrintTicket>"# |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
let ticket = PrintTicket::from_xml(xml); |
|
|
|
let ticket = PrintTicket::from_xml(xml); |
|
|
|
ticket |
|
|
|
ticket |
|
|
|
@ -153,14 +152,7 @@ fn print_document( |
|
|
|
{ |
|
|
|
{ |
|
|
|
match raw_convert::imageToPdf2(document_path.clone()) { |
|
|
|
match raw_convert::imageToPdf2(document_path.clone()) { |
|
|
|
Ok(pdf_path) => { |
|
|
|
Ok(pdf_path) => { |
|
|
|
print_document( |
|
|
|
print_document(device_name, pdf_path, dpi, color, size, quality); |
|
|
|
device_name, |
|
|
|
|
|
|
|
pdf_path, |
|
|
|
|
|
|
|
dpi, |
|
|
|
|
|
|
|
color, |
|
|
|
|
|
|
|
size, |
|
|
|
|
|
|
|
quality, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
Err(e) => { |
|
|
|
Err(e) => { |
|
|
|
println!("Error converting image to PDF: {}", e); |
|
|
|
println!("Error converting image to PDF: {}", e); |
|
|
|
@ -169,8 +161,6 @@ fn print_document( |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let my_device = match get_my_device(device_name.clone()) { |
|
|
|
let my_device = match get_my_device(device_name.clone()) { |
|
|
|
Some(device) => device, |
|
|
|
Some(device) => device, |
|
|
|
None => { |
|
|
|
None => { |
|
|
|
@ -195,8 +185,7 @@ fn print_document( |
|
|
|
.expect("Media size not supported by printer"); |
|
|
|
.expect("Media size not supported by printer"); |
|
|
|
builder.merge(media).unwrap(); |
|
|
|
builder.merge(media).unwrap(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// dpi
|
|
|
|
// dpi
|
|
|
|
if let Some(dpi) = &dpi { |
|
|
|
if let Some(dpi) = &dpi { |
|
|
|
let parsed_dpi = dpi |
|
|
|
let parsed_dpi = dpi |
|
|
|
@ -226,18 +215,13 @@ fn print_document( |
|
|
|
.expect("Color not supported by printer"); |
|
|
|
.expect("Color not supported by printer"); |
|
|
|
|
|
|
|
|
|
|
|
builder.merge(supported_color).unwrap(); |
|
|
|
builder.merge(supported_color).unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// let default_ticket = default_ticket(quality);
|
|
|
|
// let default_ticket = default_ticket(quality);
|
|
|
|
// if let Err(e) = builder.merge(default_ticket) {
|
|
|
|
// if let Err(e) = builder.merge(default_ticket) {
|
|
|
|
// println!("Failed to merge default ticket: {:?}", e);
|
|
|
|
// println!("Failed to merge default ticket: {:?}", e);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let ticket = builder.build().unwrap(); |
|
|
|
let ticket = builder.build().unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
// let xml=ticket.get_xml();
|
|
|
|
// let xml=ticket.get_xml();
|
|
|
|
@ -250,13 +234,11 @@ fn print_document( |
|
|
|
// let theprinter = ImagePrinter::new(my_device);
|
|
|
|
// let theprinter = ImagePrinter::new(my_device);
|
|
|
|
|
|
|
|
|
|
|
|
printer.print(path, ticket).unwrap(); |
|
|
|
printer.print(path, ticket).unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)] |
|
|
|
#[cfg_attr(mobile, tauri::mobile_entry_point)] |
|
|
|
pub fn run() { |
|
|
|
pub fn run() { |
|
|
|
tauri::Builder::default() |
|
|
|
tauri::Builder::default() |
|
|
|
|
|
|
|
.plugin(tauri_plugin_http::init()) |
|
|
|
.plugin(tauri_plugin_fs::init()) |
|
|
|
.plugin(tauri_plugin_fs::init()) |
|
|
|
.plugin(tauri_plugin_dialog::init()) |
|
|
|
.plugin(tauri_plugin_dialog::init()) |
|
|
|
.plugin(tauri_plugin_opener::init()) |
|
|
|
.plugin(tauri_plugin_opener::init()) |
|
|
|
|