aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorTeddy Wing2019-11-01 21:47:46 +0100
committerTeddy Wing2019-11-01 21:47:46 +0100
commit2a6496c631faba7d5f8c69c514e8db9d5f0c0b35 (patch)
tree7792461ff1473b00473cc58cfb81dee88be98d33 /src/lib.rs
parent95eba1ff9ca62395e7fae7b4f1f260abea66d40a (diff)
downloadpdf-urls-2a6496c631faba7d5f8c69c514e8db9d5f0c0b35.tar.bz2
main: Move URL extraction code into lib.rs
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs38
1 files changed, 38 insertions, 0 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());
+
+ ()
+ },
+ _ => (),
+ }
+ }
+ }
+ }
+ }
+
+ ()
+ },
+ _ => (),
+ }
+ }
+}