-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathprint_with_options.rs
More file actions
78 lines (67 loc) · 2.39 KB
/
print_with_options.rs
File metadata and controls
78 lines (67 loc) · 2.39 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use cups_rs::*;
fn main() -> Result<()> {
println!("CUPS Print with Options Example");
println!("===============================");
let args: Vec<String> = std::env::args().collect();
let file_path = if args.len() > 1 {
args[1].clone()
} else {
let content = "Print Options Test\n\nTesting various print settings:\n- Copies\n- Quality\n- Color mode\n- Duplex\n";
std::fs::write("options_test.txt", content)?;
"options_test.txt".to_string()
};
let printer_name = args.get(2).cloned().unwrap_or_else(|| "PDF".to_string());
let destination = get_destination(&printer_name)?;
// Test different option combinations
let test_cases = vec![
("Basic print", PrintOptions::new()),
("Multiple copies", PrintOptions::new().copies(2)),
(
"High quality color",
PrintOptions::new()
.color_mode(ColorMode::Color)
.quality(PrintQuality::High),
),
(
"Duplex on A4",
PrintOptions::new()
.duplex(DuplexMode::TwoSidedPortrait)
.media(MEDIA_A4),
),
(
"Custom settings",
PrintOptions::new()
.copies(3)
.color_mode(ColorMode::Monochrome)
.quality(PrintQuality::Draft)
.orientation(Orientation::Landscape),
),
];
for (name, options) in test_cases {
println!("\n--- {} ---", name);
// Show options being used
if !options.is_empty() {
println!("Options:");
for (key, value) in options.as_cups_options() {
println!(" {}: {}", key, value);
}
}
// Create job with specific options
match create_job_with_options(&destination, &format!("{} test", name), &options) {
Ok(job) => {
println!("Created job {}", job.id);
// Submit and start printing
if job.submit_file(&file_path, FORMAT_TEXT).is_ok() {
job.close().ok();
println!("Job submitted and started");
}
}
Err(e) => println!("Failed: {}", e),
}
}
if file_path == "options_test.txt" {
std::fs::remove_file("options_test.txt").ok();
}
println!("\nAll test jobs submitted. Check: lpstat -o");
Ok(())
}