From a6b23b8dd102b8be935292b2b27b180d3925cbc1 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 4 May 2021 21:19:00 +0200 Subject: Get variables from command line arguments --- src/main.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') 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> { let args: Vec = 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(()) } -- cgit v1.2.3