Class: Pdfrb::Task::ExtractText::TextCollector
- Inherits:
-
Content::Processor
- Object
- Content::Processor
- Pdfrb::Task::ExtractText::TextCollector
- Defined in:
- lib/pdfrb/task/extract_text.rb
Overview
Internal: collects bytes from Tj / TJ / ' / +"'.
Tracks text-matrix y to insert line breaks at vertical moves.
Resolves glyph codes to Unicode via the active font's
/ToUnicode CMap or /Encoding.
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Attributes inherited from Content::Processor
Instance Method Summary collapse
-
#initialize(document, page) ⇒ TextCollector
constructor
A new instance of TextCollector.
- #move_text(tx, ty) ⇒ Object
- #show_text(str) ⇒ Object
- #show_text_array(arr) ⇒ Object
- #update_text_state(**overrides) ⇒ Object
Methods inherited from Content::Processor
#apply_extgstate, #begin_marked_content, #end_marked_content, #marked_content_point, #paint_path, #path_close, #path_curve_to, #path_end, #path_line_to, #path_move_to, #path_rectangle, #pop_graphics_state, #process, #push_graphics_state, #set_text_matrix, #update_graphics_state
Constructor Details
#initialize(document, page) ⇒ TextCollector
Returns a new instance of TextCollector.
41 42 43 44 45 46 47 48 |
# File 'lib/pdfrb/task/extract_text.rb', line 41 def initialize(document, page) super() @document = document @page = page @text = +"" @last_y = nil @font_resolver = FontResolver.new(document, page) end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
39 40 41 |
# File 'lib/pdfrb/task/extract_text.rb', line 39 def text @text end |
Instance Method Details
#move_text(tx, ty) ⇒ Object
65 66 67 68 |
# File 'lib/pdfrb/task/extract_text.rb', line 65 def move_text(tx, ty, **) super check_line_break end |
#show_text(str) ⇒ Object
50 51 52 53 |
# File 'lib/pdfrb/task/extract_text.rb', line 50 def show_text(str) check_line_break @text << decode(str) end |
#show_text_array(arr) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/pdfrb/task/extract_text.rb', line 55 def show_text_array(arr) check_line_break arr.each do |e| case e when ::String then @text << decode(e) when Numeric then next # kerning adjustment; ignore end end end |
#update_text_state(**overrides) ⇒ Object
70 71 72 73 |
# File 'lib/pdfrb/task/extract_text.rb', line 70 def update_text_state(**overrides) super @font_resolver.activate(graphics_state.text_state.font_name) if overrides.key?(:font_name) end |