# encoding: utf-8 # # All of the previous styling options we've seen deal with all the table cells # at once. # # With initializer blocks we may deal with specific cells. # A block passed to one of the table methods (Prawn::Table.new, # Prawn::Document#table, Prawn::Document#make_table) # will be called after cell setup but before layout. This is a very flexible way # to specify styling and layout constraints. # # Just like the Prawn::Document.generate method, the table # initializer blocks may be used with and without a block argument. # # The table class has three methods that are handy within an initializer block: # cells, rows and columns. All three # return an instance of Prawn::Table::Cells which represents # a selection of cells. # # cells return all the table cells, while rows and # columns accept a number or a range as argument which returns a # single row/column or a range of rows/columns respectively. (rows # and columns are also aliased as row and # column) # # The Prawn::Table::Cells class also defines rows and # columns so they may be chained to narrow the selection of cells. # # All of the cell styling options we've seen on previous examples may be set as # properties of the selection of cells. # require File.expand_path(File.join(File.dirname(__FILE__), %w[.. example_helper])) filename = File.basename(__FILE__).gsub('.rb', '.pdf') Prawn::Example.generate(filename) do data = [ ["Header", "A " * 5, "B"], ["Data row", "C", "D " * 5], ["Another data row", "E", "F"]] table(data) do cells.padding = 12 cells.borders = [] row(0).borders = [:bottom] row(0).border_width = 2 row(0).font_style = :bold columns(0..1).borders = [:right] row(0).columns(0..1).borders = [:bottom, :right] end end