diff options
author | Teddy Wing | 2021-05-04 21:19:00 +0200 |
---|---|---|
committer | Teddy Wing | 2021-05-04 21:19:00 +0200 |
commit | a6b23b8dd102b8be935292b2b27b180d3925cbc1 (patch) | |
tree | b7c2375459f5c297df6338f272b03102a61b6e34 /src/main.rs | |
parent | 6b25d87d570d5b0950231a7809bf1913af9c5a9d (diff) | |
download | pdf-form-replace-font-a6b23b8dd102b8be935292b2b27b180d3925cbc1.tar.bz2 |
Get variables from command line arguments
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index e9e198d..4dc7ddb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use lopdf::{Document, Object}; use std::env; -fn main() { +fn main() -> Result<(), Box<dyn std::error::Error>> { let args: Vec<String> = env::args().collect(); let mut opts = Options::new(); @@ -20,12 +20,14 @@ fn main() { let input_pdf = if opt_matches.free.is_empty() { "-" } else { - opt_matches.free[0] + &opt_matches.free[0] }; - let output_pdf = opt_matches.opt_str("output").unwrap_or("-"); + let find = opt_matches.opt_str("find").unwrap(); + let replace = opt_matches.opt_str("replace").unwrap(); + let output_pdf = opt_matches.opt_str("output").unwrap_or("-".to_owned()); - let mut doc = Document::load("./f1040.pdf").unwrap(); + let mut doc = Document::load(input_pdf).unwrap(); for (_, mut obj) in &mut doc.objects { match &mut obj { @@ -38,7 +40,7 @@ fn main() { let new_properties = std::str::from_utf8(properties) .unwrap() - .replace("HelveticaLTStd-Bold", "CourierNewPSMT"); + .replace(&find, &replace); *properties = new_properties.into_bytes(); } @@ -48,5 +50,7 @@ fn main() { } } - doc.save("./new.pdf").unwrap(); + doc.save(output_pdf).unwrap(); + + Ok(()) } |