public
Description: Fast, Nimble PDF Writer for Ruby
Homepage: http://prawn.majesticseacreature.com
Clone URL: git://github.com/sandal/prawn.git
prawn / examples / fancy_table.rb
100644 48 lines (37 sloc) 1.546 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# encoding: utf-8
 
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require "prawn"
require "rubygems"
require "fastercsv"
 
headers, *body = FasterCSV.read("#{Prawn::BASEDIR}/examples/addressbook.csv")
 
Prawn::Document.generate("fancy_table.pdf", :page_layout => :landscape) do
 
  mask(:y) { table body, :headers => headers, :align => :center }
 
  table [["This is", "A Test" ],
         [ Prawn::Graphics::Cell.new( :text => "Of tables",
                                       :background_color => "ffccff" ),
          "Drawn Side"], ["By side", "and stuff" ]],
    :position => 600,
    :headers => ["Col A", "Col B"],
    :border => 1,
    :vertical_padding => 5,
    :horizontal_padding => 3,
    :font_size => 10,
    :row_colors => :pdf_writer,
    :widths => { 1 => 50 }
 
  move_down 150
 
  table [%w[1 2 3],%w[4 5 6],%w[7 8 9]],
    :position => :center,
    :border_style => :grid,
    :font_size => 40
 
  cell [500,300],
    :text => "This free flowing textbox shows how you can use Prawn's "+
      "cells outside of a table with ease. Think of a 'cell' as " +
      "simply a limited purpose bounding box that is meant for laying " +
      "out blocks of text and optionally placing a border around it",
    :width => 225, :padding => 10, :border => 2
 
  font_size! 24
  cell [50,75],
    :text => "This document demonstrates a number of Prawn's table features",
    :border_style => :no_top, # :all, :no_bottom, :sides
    :horizontal_padding => 5, :border => 1
 
end