Class | Prawn::FlexibleTable |
In: |
lib/prawn/flexible-table/cell.rb
lib/prawn/flexible-table.rb |
Parent: | Object |
This class implements simple PDF flexible table generation.
Prawn tables have the following features:
* Can be generated with or without headers * Can tweak horizontal and vertical padding of text * Minimal styling support (borders / row background colors) * Can be positioned by bounding boxes (left/center aligned) or an absolute x position * Automated page-breaking as needed * Column widths can be calculated automatically or defined explictly on a column by column basis * Text alignment can be set for the whole table or by column * Cells can have both rowspan and colspan attributes
The current implementation is a bit barebones, but covers most of the basic needs for PDF table generation. If you have feature requests, please share them at: groups.google.com/group/prawn-ruby
Creates a new Document::FlexibleTable object. This is generally called indirectly through Document#flexible_table but can also be used explictly.
The data argument is a two dimensional array of either string, FlexibleTable::Cell or hashes (with the options to create a Cell object), organized by row, e.g.:
[["r1-col1","r1-col2"],["r2-col2","r2-col2"]] [ [ {:text => "r1-2 col1-2", :rowspan => 2, :colspan => 2}, "r1-col3"], [ {:text => "r2 col 3", :text_color => "EEAAFF" } ], [ "r3 col1", "r3 col2", "r3 col3" ] ]
As with all Prawn text drawing operations, strings must be UTF-8 encoded.
The following options are available for customizing your tables, with defaults shown in [] at the end of each description.
:headers: | An array of table headers, either strings or Cells. [Empty] |
:align_headers: | Alignment of header text. Specify for entire header (:left) or by column ({ 0 => :right, 1 => :left}). If omitted, the header alignment is the same as the column alignment. |
:header_text_color: | Sets the text color of the headers |
:header_color: | Manually sets the header color |
:font_size: | The font size for the text cells . [12] |
:horizontal_padding: | The horizontal cell padding in PDF points [5] |
:vertical_padding: | The vertical cell padding in PDF points [5] |
:padding: | Horizontal and vertical cell padding (overrides both) |
:border_width: | With of border lines in PDF points [1] |
:border_style: | If set to :grid, fills in all borders. If set to :underline_header, underline header only. Otherwise, borders are drawn on columns only, not rows |
:border_color: | Sets the color of the borders. |
:position: | One of :left, :center or n, where n is an x-offset from the left edge of the current bounding box |
:width:: | A set width for the table, defaults to the sum of all column widths |
:column_widths:: | A hash of indices and widths in PDF points. E.g. { 0 => 50, 1 => 100 } |
:row_colors: | An array of row background colors which are used cyclicly. |
:align: | Alignment of text in columns, for entire table (:center) or by column ({ 0 => :left, 1 => :center}) |
Row colors are specified as html encoded values, e.g. ["ffffff","aaaaaa","ccaaff"]. You can also specify :row_colors => :pdf_writer if you wish to use the default color scheme from the PDF::Writer library.
See Document#flexible_table for typical usage, as directly using this class is not recommended unless you know why you want to do it.