Skip to content

Commit

Permalink
Support scanning to pdf or jpg
Browse files Browse the repository at this point in the history
Alas it doesn't ask the printer what it can do beforehand. That still
needs to be added to the list of capabilities.
  • Loading branch information
tanuva committed Dec 6, 2023
1 parent 35f2c3c commit 4e0c100
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions escl-scan-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ impl From<CliColorMode> for String {
}
}

#[derive(Clone, ValueEnum)]
enum CliOutputFormat {
JPG,
PDF,
}

impl From<CliOutputFormat> 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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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();

Check failure on line 167 in escl-scan-cli/src/main.rs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, stable)

no field `input_format` on type `ScanSettings`

Check failure on line 167 in escl-scan-cli/src/main.rs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, nightly)

no field `input_format` on type `ScanSettings`

if let Err(err) = scanner.scan(&scan_settings, &args.output_file_name) {
eprintln!("Failed to scan: {err:?}");
Expand Down
1 change: 1 addition & 0 deletions escl-scan/src/scanner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 2 additions & 0 deletions escl-scan/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 4e0c100

Please sign in to comment.