-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathpdf.rs
More file actions
26 lines (22 loc) · 749 Bytes
/
pdf.rs
File metadata and controls
26 lines (22 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use atomic_lib::resources::PropVals;
const CONTENT_PROP: &str = atomic_lib::urls::DESCRIPTION;
/// Extracts the text from a PDF file.
pub fn atomize(mut file: crate::file::File) -> PropVals {
let mut props = PropVals::new();
let bytes = file.bytes();
let text = pdf_extract::extract_text_from_mem(&bytes).unwrap();
props.insert(CONTENT_PROP.into(), atomic_lib::Value::Markdown(text));
props
}
#[cfg(test)]
mod tests {
use super::*;
use crate::file::File;
#[test]
fn load_pdf() {
let f = File::open("./test/docs-demo.pdf").unwrap();
let propvals = f.to_propvals();
let content = propvals.get(CONTENT_PROP).unwrap();
assert!(content.to_string().contains("Atomic Data"));
}
}