Module: Prawn::Templates

Defined in:
lib/prawn/templates.rb

Instance Method Summary collapse

Instance Method Details

#initialize_first_page(options) ⇒ Object



7
8
9
10
11
12
# File 'lib/prawn/templates.rb', line 7

def initialize_first_page(options)
  return super unless options[:template]

  fresh_content_streams(options)
  go_to_page(1)
end

#merge_template_options(page_options, options) ⇒ Object



67
68
69
70
# File 'lib/prawn/templates.rb', line 67

def merge_template_options(page_options, options)
  object_id = state.store.import_page(options[:template], options[:template_page] || 1)
  page_options.merge!(:object_id => object_id, :page_template => true)
end

#start_new_page(options = {}) ⇒ Object

FIXME: This is going to be terribly brittle because it copy-pastes the start_new_page method. But at least it should only run when templates are used.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/prawn/templates.rb', line 18

def start_new_page(options = {})
  return super unless options[:template]

  if last_page = state.page
    last_page_size    = last_page.size
    last_page_layout  = last_page.layout
    last_page_margins = last_page.margins
  end

  page_options = {:size => options[:size] || last_page_size,
                  :layout  => options[:layout] || last_page_layout,
                  :margins => last_page_margins}
  if last_page
    new_graphic_state = last_page.graphic_state.dup  if last_page.graphic_state
    #erase the color space so that it gets reset on new page for fussy pdf-readers
    new_graphic_state.color_space = {} if new_graphic_state
    page_options.merge!(:graphic_state => new_graphic_state)
  end

  merge_template_options(page_options, options)

  state.page = PDF::Core::Page.new(self, page_options)

  apply_margin_options(options)
  generate_margin_box

  # Reset the bounding box if the new page has different size or layout
  if last_page && (last_page.size != state.page.size ||
                   last_page.layout != state.page.layout)
    @bounding_box = @margin_box
  end

  state.page.new_content_stream
  use_graphic_settings(true)
  forget_text_rendering_mode!

  unless options[:orphan]
    state.insert_page(state.page, @page_number)
    @page_number += 1

    canvas { image(@background, :scale => @background_scale, :at => bounds.top_left) } if @background
    @y = @bounding_box.absolute_top

    float do
      state.on_page_create_action(self)
    end
  end
end