aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorTeddy Wing2021-05-04 21:30:30 +0200
committerTeddy Wing2021-05-04 21:30:30 +0200
commit177c51d7af7626afc98a8c2e0abe8bb4a6529121 (patch)
tree1ec0dadcffdb3c77e45522a14cdd0be3c09c920c /src/main.rs
parenta6b23b8dd102b8be935292b2b27b180d3925cbc1 (diff)
downloadpdf-form-replace-font-177c51d7af7626afc98a8c2e0abe8bb4a6529121.tar.bz2
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.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs12
1 files changed, 10 insertions, 2 deletions
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<dyn std::error::Error>> {
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<dyn std::error::Error>> {
}
}
- doc.save(output_pdf).unwrap();
+ if output_pdf == "-" {
+ doc.save_to(&mut std::io::stdout()).unwrap();
+ } else {
+ doc.save(output_pdf).unwrap();
+ }
Ok(())
}