File: page.rb

package info (click to toggle)
ruby-pdf-inspector 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 176 kB
  • sloc: ruby: 293; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 743 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'forwardable'

module PDF
  class Inspector
    class Page < Inspector
      extend Forwardable

      attr_reader :pages

      def_delegators :@state, :set_text_font_and_size

      def initialize
        @pages = []
      end

      def page=(page)
        @pages << { size: page.attributes[:MediaBox][-2..-1], strings: [] }
        @state = PDF::Reader::PageState.new(page)
      end

      def show_text(*params)
        params.each do |param|
          @pages.last[:strings] << @state.current_font.to_utf8(param)
        end
      end

      def show_text_with_positioning(*params)
        # ignore kerning information
        show_text params[0].reject { |e|
          e.is_a? Numeric
        }.join
      end
    end
  end
end