Class | Prawn::Document
In: | lib/prawn/layout/grid.rb lib/prawn/layout/page.rb lib/prawn/table/cell.rb lib/prawn/table.rb
Parent: | Object

### Methods

cell define_grid footer grid header lazy_bounding_box padded_box table

### Classes and Modules

Class Prawn::Document::Box
Class Prawn::Document::Grid
Class Prawn::Document::LazyBoundingBox
Class Prawn::Document::MultiBox

### Public Instance methods

cell(point, options={})

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

define_grid(options = {})

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

footer(top_left,options={},&block)

A footer is a LazyBoundingBox drawn relative to the margins that can be repeated on every page of the document.

Unless `:width` or `:height` are specified, the margin_box width and height are used.

      footer [margin_box.left, margin_box.bottom + 25] do
        stroke_horizontal_rule
        text "And here's a sexy footer", :size => 16
      end

grid(*args)

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]

header(top_left,options={},&block)

A header is a LazyBoundingBox drawn relative to the margins that can be repeated on every page of the document.

Unless `:width` or `:height` are specified, the margin_box width and height are used.

      header margin_box.top_left do
       text "Here's My Fancy Header", :size => 25, :align => :center
       stroke_horizontal_rule
     end

lazy_bounding_box(*args,&block)

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

padded_box(margin, &block)

A bounding box with the same dimensions of its parents, minus a margin on all sides

table(data, options={})

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.

[Validate]