Class: PdfExtract::PdfView

Inherits:
AbstractView show all
Defined in:
lib/view/pdf_view.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractView

#auto_color, #initialize, #objects, #singular_name

Constructor Details

This class inherits a constructor from PdfExtract::AbstractView

Class Method Details

.write(render, filename) ⇒ Object



37
38
39
# File 'lib/view/pdf_view.rb', line 37

def self.write render, filename
  render.render_file filename
end

Instance Method Details

#render(options = {}) ⇒ Object



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
# File 'lib/view/pdf_view.rb', line 7

def render options={}
  Prawn::Document.new :template => @filename do |doc|
    objects.each_pair do |type, objs|
      last_page = 1
      color = auto_color
      doc.go_to_page last_page
      doc.fill_color color
      
      objs.each do |obj|
        unless obj[:page].nil?
          if obj[:page] != last_page
            last_page = obj[:page]
            doc.go_to_page last_page
            doc.fill_color color
          end
          
          # XXX Works, but why?
          pos = [obj[:x] - 36, obj[:y] + obj[:height] - 36]
          width = obj[:width]
          height = obj[:height]
          
          doc.transparent 0.2 do
            doc.fill_rectangle pos, width, height
          end
        end
      end
    end
  end
end