Created
May 10, 2009 15:20
-
-
Save amoeba/109631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'prawn' | |
require 'prawn/layout' | |
Prawn::Document.generate("table-test.pdf") do | |
headers = ["Course", "Grade", "Comments"] | |
data = [["Home Room", "A+", "Great work!"], | |
["Home Room", "A+", "Great work!"], | |
["Home Room", "A+", "Great work!"], | |
["Home Room", "A+", "Great work!"], | |
["Home Room", "A+", "Great work!"]] | |
def make_table(headers, data) | |
table( | |
data, | |
:headers => headers, | |
:font_size => 8, | |
:border_style => :grid, | |
:border_width => 0.5, | |
:width => bounds.width) | |
end | |
text "Report for all students" | |
bounding_box( # Main bounding box for the boxes | |
[bounds.left, bounds.height - 20], | |
:width => bounds.width, | |
:height => bounds.height - 20) do | |
bounding_box( | |
bounds.top_left, | |
:width => bounds.width / 2, | |
:height => bounds.height / 3) do | |
#stroke_bounds | |
padded_box(10) do | |
text "Student Name" | |
make_table(headers,data) | |
end | |
end | |
bounding_box( | |
[bounds.left + bounds.width / 2, bounds.top], | |
:width => bounds.width / 2, | |
:height => bounds.height / 3) do | |
#stroke_bounds | |
padded_box(10) do | |
text "Student Name" | |
make_table(headers,data) | |
end | |
end | |
bounding_box( | |
[bounds.left, bounds.top - bounds.height / 3], | |
:width => bounds.width / 2, | |
:height => bounds.height / 3) do | |
#stroke_bounds | |
padded_box(10) do | |
text "Student Name" | |
make_table(headers,data) | |
end | |
end | |
bounding_box( | |
[bounds.left + bounds.width / 2, bounds.top - bounds.height / 3], | |
:width => bounds.width / 2, | |
:height => bounds.height / 3) do | |
#stroke_bounds | |
padded_box(10) do | |
text "Student Name" | |
make_table(headers,data) | |
end | |
end | |
bounding_box( | |
[bounds.left, bounds.height / 3], | |
:width => bounds.width / 2, | |
:height => bounds.height / 3) do | |
#stroke_bounds | |
padded_box(10) do | |
text "Student Name" | |
make_table(headers,data) | |
end | |
end | |
bounding_box( | |
[bounds.left + bounds.width / 2, bounds.bottom + bounds.height / 3], | |
:width => bounds.width / 2, | |
:height => bounds.height / 3) do | |
#stroke_bounds | |
padded_box(10) do | |
text "Student Name" | |
make_table(headers,data) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment