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

Methods

Classes and Modules

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

Public Instance methods

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

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

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]

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

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

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]