pdf-reader icon indicating copy to clipboard operation
pdf-reader copied to clipboard

Would the author be interested in a text_at page function?

Open 3ynm opened this issue 2 years ago • 2 comments

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.

3ynm avatar Jun 13 '23 16:06 3ynm

#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?

yob avatar Jun 14 '23 11:06 yob

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

3ynm avatar Jun 14 '23 15:06 3ynm