Class: PDF::Reader::MarkupPage::PageBoldItalicReceiver

Inherits:
PageTextReceiver
  • Object
show all
Defined in:
lib/pdf/reader/markup/page_bold_italic_receiver.rb

Overview

Builds a UTF-8 plaintext string and a UTF-8 string that includes simple Bold and Italic markup of all the text on a single page by processing all the operators in a content stream.

Instance Method Summary collapse

Instance Method Details

#contentObject

Returns the value of the content attribute



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pdf/reader/markup/page_bold_italic_receiver.rb', line 49

def content
  lines = super.lines.to_a
  fixed = []
  current_line = 0
  offset = 0
  formatted_lines = markup.lines.to_a
  lines.each_with_index do |line, index|
    formatted_line = formatted_lines[index + offset]
    if line.strip == "" and (formatted_line and formatted_lines[index + offset].strip != "")
      offset -= 1
    else
      fixed << line
    end
  end
  lines = fixed.join("")
  lines
end

#markupObject

Returns the value of the markup attribute - equivalent to the content attribute but with bold and italic markup



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pdf/reader/markup/page_bold_italic_receiver.rb', line 29

def markup
  unless @text.empty?
    line = fix_markup("#{@text.join("").strip}#{@last_tag_end}")
    @lines << line
    @text = []
  end
  if @footer.join("").strip.empty?
    if @lines.last.empty?
      output = @lines[0..-2].join("\n")
    else
      output = @lines.join("\n")
    end
  else
    output = %Q|#{@lines.join("\n")}\n#{@footer.join("")}|
  end
  output
end

#page=(page) ⇒ Object

starting a new page



16
17
18
19
20
21
22
23
24
# File 'lib/pdf/reader/markup/page_bold_italic_receiver.rb', line 16

def page=(page)
  super(page)
  @last_tag_end = ""
  @open_tag = ""
  @lasty = 0.0
  @footer = []
  @text = []
  @lines = []
end