Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added extract_text_by_page() #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JustBobinAround
Copy link

I needed to be able to extract text by page number, so I added the feature. Please let me know if you want a different name or if the function already exists.


pub fn output_doc_page(doc: &Document, output: &mut dyn OutputDev, page: u32) -> Result<(), OutputError> {
if let Ok(_) = doc.trailer.get(b"Encrypt") {
eprintln!("Encrypted documents are not currently supported: See https://github.com/J-F-Liu/lopdf/issues/168")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was copied from an older version of output_doc?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, its just to pass the page number wanted and to remove the for loop that runs through each page. I needed access to the text per page in a set of documents for a vector DB I'm writing right now. Also, I was wondering if I could write a prelude module for this because currently the Document struct from lopdf is not accessible unless the user adds the same version to their own Cargo.toml. If the user does not import the crate and call output_doc_page() with a reference to the loaded Document struct, then they are forced to call extract_text_by_page which forces a read from file every time they want to read a page. So if I made a prelude module to include the appropriate crates as accessible to the user, it would resolve the issue. I'll submit that in a different pull request if you want.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe accept a reference to a document instead of path will be better? Since if we have multiple page want to extract from same document, does't require load the document every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants