Class: PDFGen::Document

Inherits:
BaseRegion show all
Includes:
Canvas, CaptionContainer, Composite, DivContainer, ImageContainer, SpanContainer, TableContainer
Defined in:
lib/document.rb

Instance Attribute Summary collapse

Attributes inherited from BaseRegion

#parent

Attributes included from BaseAttributes

#background_color, #border_bottom, #border_color, #border_left, #border_right, #border_style, #border_top, #border_width, #height, #is_breakable, #pad_bottom, #pad_left, #pad_right, #pad_top, #page_pad_top, #width

Instance Method Summary collapse

Methods included from Canvas

#y, #y=

Methods included from Composite

#[], #add_region, #apply_values, #elements, #page_pad_top=, #regions, #render_regions

Methods included from TableContainer

#table

Methods included from CaptionContainer

#caption

Methods included from SpanContainer

#span

Methods included from DivContainer

#div

Methods included from ImageContainer

#image

Methods inherited from BaseRegion

#check_fit_in_height, #document, #minimal_height, #set_properties, #value

Methods included from BaseAttributes

#av_width, #border=, #border_params, #breakable?, included, #paddings=, #var_init

Methods included from BaseAttributes::ClassMethods

#common_setter

Constructor Details

#initialize(pdf, page_pad_top) ⇒ Document

Returns a new instance of Document.



16
17
18
19
20
21
22
23
24
25
# File 'lib/document.rb', line 16

def initialize(pdf, page_pad_top)
  super(nil)
  pdf.y += pdf.top_margin # clear predefined top_margin
  pdf.y -= page_pad_top # set y considering page_pad_top
  pdf.top_margin = 0

  @pdf = pdf
  @page_pad_top = page_pad_top
  @header = []
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



27
28
29
# File 'lib/document.rb', line 27

def header
  @header
end

#pdfObject (readonly)

Returns the value of attribute pdf.



27
28
29
# File 'lib/document.rb', line 27

def pdf
  @pdf
end

Instance Method Details

#break_pageObject

creates new page



30
31
32
# File 'lib/document.rb', line 30

def break_page
  pdf.page_break @page_pad_top
end

#renderObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/document.rb', line 34

def render
  pos = [0, pdf.y]
  regions.each do |region|
    pos[1] = pdf.y
    status = region.render(pos, pdf.y)
    if status[1]
      pdf.y -= status[0]
    else
      self.break_page          
      redo
    end
  end
end