diff options
| author | WriterV2 <primary-v2@protonmail.com> | 2023-04-10 13:44:53 +0200 |
|---|---|---|
| committer | WriterV2 <primary-v2@protonmail.com> | 2023-04-10 13:44:53 +0200 |
| commit | aa191707ba93ee1b0790be89dcb274864ffe884f (patch) | |
| tree | ffe853e5716fc9505a11bfe5d4f3e6e9e19e2d20 /src/works | |
| parent | 655cd12e1d6dc0b68695e888ab1919e0387ee0ce (diff) | |
Add number of pdf pages automation
Diffstat (limited to 'src/works')
| -rw-r--r-- | src/works/stories.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/works/stories.rs b/src/works/stories.rs index c2b4b8f..510f30b 100644 --- a/src/works/stories.rs +++ b/src/works/stories.rs @@ -13,9 +13,10 @@ struct Story { title: String, description: String, path_to_document: String, - number_of_pages: u16, language: Language, #[serde(default)] + number_of_pages: u32, + #[serde(default)] last_update: NaiveDate, } @@ -47,6 +48,7 @@ impl super::Works for Stories { let mut stories: Stories = serde_json::from_reader(std::io::BufReader::new(&file))?; for story in stories.0.iter_mut() { story.get_last_modified()?; + story.get_pages_num()?; } // add error context Ok(stories) @@ -99,7 +101,7 @@ impl Story { anyhow::Ok(text).with_context(|| format!("Failed to extract text for {}", self.title)) } - // get date of last modification of pdf file + // get date of last modification fn get_last_modified(&mut self) -> anyhow::Result<chrono::NaiveDate> { use std::os::linux::fs::MetadataExt; let pdf_last_modification = std::fs::metadata(self.get_pdf_path())?.st_mtime(); @@ -108,6 +110,13 @@ impl Story { self.last_update = date; Ok(date) } + + // get number of pages of pdf file + fn get_pages_num(&mut self) -> anyhow::Result<u32> { + let file = pdf::file::File::open(self.get_pdf_path())?; + self.number_of_pages = file.num_pages(); + Ok(file.num_pages()) + } } // language of story content |
