From 7f14b37cb7457ec0e9aff7054480093bba7ae571 Mon Sep 17 00:00:00 2001 From: Sean McEligot Date: Sun, 12 Mar 2023 16:57:59 -0400 Subject: [PATCH] update api calls and cleaup output --- src/bin/pdf2text.rs | 15 ++++++++------- src/lib.rs | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/bin/pdf2text.rs b/src/bin/pdf2text.rs index 8495f91..70a5996 100644 --- a/src/bin/pdf2text.rs +++ b/src/bin/pdf2text.rs @@ -1,18 +1,19 @@ -use pdf::file::File; +use std::{env, path::PathBuf}; + +use pdf::file::FileOptions; use pdf_tools::page_text; fn main() { - let input = std::env::args().nth(1).expect("no input file given"); - let file = File::open(input).expect("failed to read PDF"); - for (page_nr, page) in file.pages().enumerate() { + let path = PathBuf::from(env::args_os().nth(1).expect("no file given")); + let file = FileOptions::cached().open(&path).unwrap(); + + for (_page_nr, page) in file.pages().enumerate() { if let Ok(page) = page { - println!("=== PAGE {} ===\n", page_nr); if let Ok(text) = page_text(&page, &file) { - println!("{}", text); + print!("{}", text); } else { println!("ERROR"); } - println!(); } } } diff --git a/src/lib.rs b/src/lib.rs index ba8d741..1ea6868 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -273,7 +273,7 @@ pub fn page_text(page: &Page, resolve: &impl Resolve) -> Result { if translation.y.abs() < f32::EPSILON { - out.push('\n'); + //out.push('\n'); } } Op::SetTextMatrix { matrix } => {