Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created June 16, 2010 21:17
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save practicingruby/441285 to your computer and use it in GitHub Desktop.
Save practicingruby/441285 to your computer and use it in GitHub Desktop.
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
@TylerRick
Copy link

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)

@quentindemetz
Copy link

link is down

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment