aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs38
-rw-r--r--src/main.rs37
2 files changed, 40 insertions, 35 deletions
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..fbe8b8a
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,38 @@
+extern crate lopdf;
+
+use lopdf::{Document, Object};
+
+pub fn get_urls_from_pdf() {
+ let doc = Document::load("example.pdf").unwrap();
+
+ for (_, obj) in doc.objects {
+ match obj {
+ Object::Dictionary(d) => {
+ for (k, v) in d.iter() {
+ let key = ::std::str::from_utf8(&k).unwrap();
+
+ if key == "A" {
+ for (k, v) in v.as_dict().unwrap() {
+ let key = ::std::str::from_utf8(&k).unwrap();
+
+ if key == "URI" {
+
+ match v {
+ Object::String(s, _) => {
+ println!("{}", ::std::str::from_utf8(s).unwrap());
+
+ ()
+ },
+ _ => (),
+ }
+ }
+ }
+ }
+ }
+
+ ()
+ },
+ _ => (),
+ }
+ }
+}
diff --git a/src/main.rs b/src/main.rs
index 4b2d541..3964551 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,38 +1,5 @@
-extern crate lopdf;
-
-use lopdf::{Document, Object};
+use pdf_urls::get_urls_from_pdf;
fn main() {
- let doc = Document::load("example.pdf").unwrap();
-
- for (_, obj) in doc.objects {
- match obj {
- Object::Dictionary(d) => {
- for (k, v) in d.iter() {
- let key = ::std::str::from_utf8(&k).unwrap();
-
- if key == "A" {
- for (k, v) in v.as_dict().unwrap() {
- let key = ::std::str::from_utf8(&k).unwrap();
-
- if key == "URI" {
-
- match v {
- Object::String(s, _) => {
- println!("{}", ::std::str::from_utf8(s).unwrap());
-
- ()
- },
- _ => (),
- }
- }
- }
- }
- }
-
- ()
- },
- _ => (),
- }
- }
+ get_urls_from_pdf();
}