How to extract pdf string in Rust?

Asked

Viewed 45 times

0

I’m trying to use the package pdf_extract to manipulate pdfs in Rust. I would like to extract the string from the pdf. I saw that the function for this is set so:

pub fn extract_text<P: AsRef<Path>>(path: P) -> Result<String, OutputError>

So I used the extract to manage the error:

use pdf_extract::extract_text;

fn main() {
    let text = extract_text("meu.pdf").expect("Unable to read file");
    println!("{}", &text)

}

This, however, returns an error:

thread 'main' panicked at 'attempted to leave type `linked_hash_map::Node<std::vec::Vec<u8>, object::Object>` uninitialized, which is invalid', /rustc/2fd73fabe469357a12c2c974c140f67e7cdd76d0/library/core/src/mem/mod.rs:671:9

As the error message is different from the one I used in expect, I don’t know what the mistake means. It seems to me, the command let text = extract_text("meu.pdf").expect("Unable to read file"); worked, but still gave error. What I’m doing wrong here?

  • 1

    I don’t know the library in question, but as far as I can tell... the expect only acts in the instance of Result which he was called. It’s not like he’s a try/catch that captures any "error" (does not exist in Rust). It seems to me that the panic! happened before the function extract_text could even have returned the Result. The panic! came from (...)/library/core/src/mem/mod.rs:671:9.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.