From 4e0c10092bef9702424810b32d885f809f4e9f45 Mon Sep 17 00:00:00 2001 From: Marcel Kummer Date: Wed, 6 Dec 2023 16:22:39 +0100 Subject: [PATCH] Support scanning to pdf or jpg Alas it doesn't ask the printer what it can do beforehand. That still needs to be added to the list of capabilities. --- escl-scan-cli/src/main.rs | 20 ++++++++++++++++++++ escl-scan/src/scanner.rs | 1 + escl-scan/src/structs.rs | 2 ++ 3 files changed, 23 insertions(+) diff --git a/escl-scan-cli/src/main.rs b/escl-scan-cli/src/main.rs index dff9da3..4ab7aca 100644 --- a/escl-scan-cli/src/main.rs +++ b/escl-scan-cli/src/main.rs @@ -30,6 +30,21 @@ impl From for String { } } +#[derive(Clone, ValueEnum)] +enum CliOutputFormat { + JPG, + PDF, +} + +impl From for String { + fn from(value: CliOutputFormat) -> Self { + match value { + CliOutputFormat::JPG => "image/jpeg".to_string(), + CliOutputFormat::PDF => "application/pdf".to_string(), + } + } +} + #[derive(clap::Parser)] #[command(author, version, about, long_about = None)] struct Cli { @@ -48,6 +63,10 @@ struct Cli { #[arg(value_name = "OUTPUT_FILE_NAME", default_value = "scan.jpg")] output_file_name: String, + /// Output document format + #[arg(short, long, value_enum, default_value = "jpg")] + output_format: CliOutputFormat, + /// Color mode #[arg(short, long, value_enum, default_value = "rgb")] color: CliColorMode, @@ -145,6 +164,7 @@ fn main() { scan_settings.x_resolution = args.dpi; scan_settings.y_resolution = args.dpi; scan_settings.color_mode = args.color.into(); + scan_settings.input_format = args.output_format.into(); if let Err(err) = scanner.scan(&scan_settings, &args.output_file_name) { eprintln!("Failed to scan: {err:?}"); diff --git a/escl-scan/src/scanner.rs b/escl-scan/src/scanner.rs index 698556a..469c11d 100644 --- a/escl-scan/src/scanner.rs +++ b/escl-scan/src/scanner.rs @@ -94,6 +94,7 @@ impl Scanner { }, input_source: "Platen".to_string(), color_mode: "RGB24".to_string(), + document_format: "image/jpeg".to_string(), x_resolution: 300, y_resolution: 300, } diff --git a/escl-scan/src/structs.rs b/escl-scan/src/structs.rs index 6cd5cff..24edfdc 100644 --- a/escl-scan/src/structs.rs +++ b/escl-scan/src/structs.rs @@ -175,6 +175,8 @@ pub struct ScanSettings { pub input_source: String, #[serde(rename = "scan:ColorMode")] pub color_mode: String, + #[serde(rename = "scan:DocumentFormatExt")] + pub document_format: String, #[serde(rename = "scan:XResolution")] pub x_resolution: i16, #[serde(rename = "scan:YResolution")]