19 lines
439 B
Ruby
19 lines
439 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "pdf-reader"
|
|
|
|
require_relative "find_text/version"
|
|
|
|
module PDF::Reader::FindText
|
|
def find_text(text)
|
|
runs(merge: false).each_cons(text.size).select do |r|
|
|
r.map(&:text).join == text
|
|
end.map do |r|
|
|
PDF::Reader::TextRun.new r.first.x, r.first.y,
|
|
r.sum(&:width), r.map(&:font_size).max, r.map(&:text).join
|
|
end
|
|
end
|
|
end
|
|
|
|
PDF::Reader::Page.include PDF::Reader::FindText
|