public
Last active

  • Download Gist
demo.rb
Ruby
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
class Demo < Prawn::Document
def flower
0.step(270, 90) do |angle|
rotate(angle, :origin => [100, 100]) do
fill_color(random_color)
polygon [100, 100], [150, 150], [200, 100]
fill_and_stroke
end
end
end
 
def flower_chain
4.times do |i|
translate(100*i, 100*i) do
flower
end
end
end
 
def flower_cross
flower_chain
 
rotate_around_center(90) do
flower_chain
end
end
 
def random_color
rgb2hex([rand(255), rand(255), rand(255)])
end
 
def rotate_around_center(angle, &block)
rotate(angle, :origin => [bounds.width/2, bounds.height/2], &block)
end
 
def text_wall
float do
text_box "The rain in Spain falls mainly on the plains. "*200,
:align => :justify, :size => 9
end
end
 
def prawn_banner
transparent(0.2) do
fill_rectangle bounds.top_left, bounds.width, bounds.height
end
 
transparent(0.75) do
font("Courier", :size => 70, :style => :bold) do
formatted_text [ { :text => "P R", :color => "000000" },
{ :text => " A ", :color => "ff0000" },
{ :text => "W N", :color => "000000" } ],
:valign => :center,
:align => :center
end
end
end
 
def github_sidebar
rotate(90, :origin => [475,300]) do
fill_rectangle [350,300], 150, 25
fill_color "ffffff"
text_box "github.com/sandal/prawn", :at => [350,300], :width => 150, :height => 25,
:valign => :center, :align => :center
end
end
 
end
 
Demo.generate("awesome.pdf", :page_size => [500,500], :margin => 0) do
text_wall
flower_cross
github_sidebar
prawn_banner
end

Nice demo. It might be worth noting that the rendered pdf output can be found at http://majesticseacreature.com/prawn-sample.pdf (as mentioned here)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.