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

Would the author be interested in a text_at page function? #517

Open
hacktivista opened this issue Jun 13, 2023 · 2 comments
Open

Would the author be interested in a text_at page function? #517

hacktivista opened this issue Jun 13, 2023 · 2 comments

Comments

@hacktivista
Copy link

I did this very basic function for getting text at certain coordinates:

def text_at(page, x1, y1, x2, y2)
  text = String.new
  page.runs.each do |r|
    next unless r.x >= x1 && r.y >= y1 && r.endx <= x2 && r.endy <= y2

    text << r.text
  end
  text
end

Probably it would be nice to have it on the library itself.

@yob
Copy link
Owner

yob commented Jun 14, 2023

#411 (shipped in 2.8.0) made the following possible:

PDF::Reader.open("somefile.pdf") do |pdf|
  puts reader.page(1).text(rect: PDF::Reader::Rectangle.new(0, 0, 100, 100))
end

Does that meet a similar need?

@hacktivista
Copy link
Author

It does. I couldn't find the available opts on the API docs, is that documented anywhere?

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

No branches or pull requests

2 participants