Skip to content

Instantly share code, notes, and snippets.

@macarthy
Created March 22, 2013 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macarthy/5219554 to your computer and use it in GitHub Desktop.
Save macarthy/5219554 to your computer and use it in GitHub Desktop.
require 'prawn'
def header
grid([0,0],[1,3]).bounding_box do
bounding_box([0,cursor], :width => 200, :height => 30) do
fill_color "d7800f"
fill_rectangle [bounds.left,bounds.top],bounds.width,bounds.height
stroke_bounds
end
end
grid([2,0],[2,7]).bounding_box do
bounding_box([0,cursor], :width => bounds.width, :height => 30) do
fill_color "aa7942"
fill_rectangle [bounds.left,bounds.top],bounds.width,bounds.height
stroke_bounds
end
end
end
def footer
grid([19,0],[19,7]).bounding_box do
bounding_box([0,cursor], :width => bounds.width, :height => 8) do
fill_color "aa7942"
fill_rectangle [bounds.left,bounds.top],bounds.width,bounds.height
stroke_bounds
end
end
end
def item
grid([3,0],[18,7]).bounding_box do
bounding_box([0,cursor], :width => bounds.width, :height => 200) do
fill_color "0433ff"
fill_rectangle [bounds.left,bounds.top],bounds.width,bounds.height
stroke_bounds
end
move_down 100
end
end
def products
5.times do
item
move_down 100
end
end
def notes
grid([3,0],[18,7]).bounding_box do
bounding_box([0,cursor], :width => bounds.width) do
text "notes"
text "notes"
text "notes"
text "notes"
text "notes"
stroke_bounds
end
end
end
def address
grid([3,0],[18,7]).bounding_box do
width = bounds.width - 4
midpoint = (width / 2) + 2
half_box_width = midpoint - 10
a = bounding_box([0, bounds.top], width: half_box_width) do
text "stuff here\n" * 4
end
@current_cursor = cursor # set bottom position
b = bounding_box([midpoint, bounds.top], width: half_box_width) do
text "stuff here\n" * 7
text "stuff here"
end
@current_cursor = cursor if cursor < @current_cursor # set bottom position if lower than left box
move_cursor_to @current_cursor
end
end
Prawn::Document.generate("test.pdf") do
define_grid(:columns => 8, :rows => 20, :gutter => 2)
repeat :all do
header
footer
end
address
products
notes
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment