aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index c09fe3e..2a59906 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -4,14 +4,18 @@ extern crate lopdf;
use std::path::Path;
use std::str;
+use std::string::String;
+use std::vec::Vec;
use lopdf::{Document, Object};
use errors::Result;
-pub fn get_urls_from_pdf<P: AsRef<Path>>(path: P) -> Result<()> {
+pub fn get_urls_from_pdf<P: AsRef<Path>>(path: P) -> Result<Vec<String>> {
let doc = Document::load(path)?;
+ let mut urls = Vec::new();
+
for (_, obj) in doc.objects {
match obj {
Object::Dictionary(d) => {
@@ -27,7 +31,7 @@ pub fn get_urls_from_pdf<P: AsRef<Path>>(path: P) -> Result<()> {
if key == "URI" {
match v {
Object::String(s, _) => {
- println!("{}", str::from_utf8(s)?);
+ urls.push(String::from_utf8(s.to_vec())?);
},
_ => (),
}
@@ -40,5 +44,5 @@ pub fn get_urls_from_pdf<P: AsRef<Path>>(path: P) -> Result<()> {
}
}
- Ok(())
+ Ok(urls)
}