From 177c51d7af7626afc98a8c2e0abe8bb4a6529121 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 4 May 2021 21:30:30 +0200 Subject: Add standard input and output handling Allow the input PDF to be read from standard input, and the output PDF to be written to standard output. --- src/main.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 4dc7ddb..7c1e077 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,11 @@ fn main() -> Result<(), Box> { 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(input_pdf).unwrap(); + let mut doc = if input_pdf == "=" { + Document::load_from(&mut std::io::stdin()).unwrap() + } else { + Document::load(input_pdf).unwrap() + }; for (_, mut obj) in &mut doc.objects { match &mut obj { @@ -50,7 +54,11 @@ fn main() -> Result<(), Box> { } } - doc.save(output_pdf).unwrap(); + if output_pdf == "-" { + doc.save_to(&mut std::io::stdout()).unwrap(); + } else { + doc.save(output_pdf).unwrap(); + } Ok(()) } -- cgit v1.2.3