Object
Builds and renders a Table::Cell. A cell is essentially a special-purpose bounding box designed for flowing text within a bordered area. For available options, see Table::Cell#new.
Prawn::Document.generate("cell.pdf") do
cell [100,500],
:width => 200,
:text => "The rain in Spain falls mainly on the plains"
end
# File lib/prawn/table/cell.rb, line 21
21: def cell(point, options={})
22: Prawn::Table::Cell.new(
23: options.merge(:document => self, :point => point)).draw
24: end
Defines the grid system for a particular document. Takes the number of rows and columns and the width to use for the gutter as the keys :rows, :columns, :gutter, :row_gutter, :column_gutter
# File lib/prawn/layout/grid.rb, line 8
8: def define_grid(options = {})
9: @grid = Grid.new(self, options)
10: end
A method that can either be used to access a particular grid on the page or work with the grid system directly.
@pdf.grid # Get the Grid directly @pdf.grid([0,1]) # Get the box at [0,1] @pdf.grid([0,1], [1,2]) # Get a multi-box spanning from [0,1] to [1,2]
# File lib/prawn/layout/grid.rb, line 19
19: def grid(*args)
20: @boxes ||= {}
21: @boxes[args] ||= if args.empty?
22: @grid
23: else
24: g1, g2 = args
25: if(g1.class == Array && g2.class == Array &&
26: g1.length == 2 && g2.length == 2)
27: multi_box(single_box(*g1), single_box(*g2))
28: else
29: single_box(g1, g2)
30: end
31: end
32: end
A LazyBoundingBox is simply a BoundingBox with an action tied to it to be executed later. The lazy_bounding_box method takes the same arguments as bounding_box, but returns a LazyBoundingBox object instead of executing the code block directly.
You can then call LazyBoundingBox#draw at any time (or multiple times if you wish), and the contents of the block will then be run. This can be useful for assembling repeating page elements or reusable components.
file = "lazy_bounding_boxes.pdf"
Prawn::Document.generate(file, :skip_page_creation => true) do
point = [bounds.right-50, bounds.bottom + 25]
page_counter = lazy_bounding_box(point, :width => 50) do
text "Page: #{page_count}"
end
10.times do
start_new_page
text "Some text"
page_counter.draw
end
end
# File lib/prawn/layout/page.rb, line 34
34: def lazy_bounding_box(*args,&block)
35: map_to_absolute!(args[0])
36: box = LazyBoundingBox.new(self,*args)
37: box.action(&block)
38: return box
39: end
A bounding box with the same dimensions of its parents, minus a margin on all sides
# File lib/prawn/layout/page.rb, line 44
44: def padded_box(margin, &block)
45: bounding_box [bounds.left + margin, bounds.top - margin],
46: :width => bounds.width - (margin * 2),
47: :height => bounds.height - (margin * 2), &block
48: end
Builds and renders a Document::Table object from raw data. For details on the options that can be passed, see Document::Table.new
data = [["Gregory","Brown"],["James","Healy"],["Jia","Wu"]]
Prawn::Document.generate("table.pdf") do
# Default table, without headers
table(data)
# Default table with headers
table data, :headers => ["First Name", "Last Name"]
# Very close to PDF::Writer's default SimpleTable output
table data, :headers => ["First Name", "Last Name"],
:font_size => 10,
:vertical_padding => 2,
:horizontal_padding => 5,
:position => :center,
:row_colors => :pdf_writer,
# Grid border style with explicit column widths.
table data, :border_style => :grid,
:column_widths => { 0 => 100, 1 => 150 }
end
Will raise <tt>Prawn::Errors::EmptyTable</tt> given
a nil or empty <tt>data</tt> paramater.
# File lib/prawn/table.rb, line 45
45: def table(data, options={})
46: if data.nil? || data.empty?
47: raise Prawn::Errors::EmptyTable,
48: "data must be a non-empty, non-nil, two dimensional array " +
49: "of Prawn::Cells or strings"
50: end
51: Prawn::Table.new(data,self,options).draw
52: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.