public
Created

Playing around with prawn for pdf-generation. See docs at http://rdoc.info/github/sandal/prawn/ and manual at http://prawn.majesticseacreature.com/manual.pdf

  • Download Gist
Gemfile
Ruby
1 2 3 4 5 6 7
source 'https://rubygems.org'
 
gem 'prawn'
 
gem 'rb-fsevent', '~> 0.9'
gem 'guard'
gem 'guard-shell'
Guardfile
Ruby
1 2 3 4 5
guard :shell do
watch(/(.*).rb/) do |m|
`ruby #{m[0]} && open #{m[1]}.pdf`
end
end
test.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
require "prawn"
require "prawn/measurement_extensions"
 
Prawn::Document.generate("test.pdf", page_size: "A4") do
text "Hello world", align: :center, size: 17.mm
move_down 1.5.cm
 
# image open("logo.png"), width: 80.mm, position: :center
 
stroke_bounds
 
font("Courier", :size => 10) do
text "Yeah, using Courier 10 courtesy of the font method."
end
 
table([ ["Ruby", "Great"], ["Java", "Not so much"] ])
 
bounding_box [100,500], width: 200, height: 100 do
stroke_bounds
text "happy days "*10
end
 
stroke_color "FF0000"
fill_color "00ff00"
self.line_width = 10
stroke do
move_to 0, 0
line_to 100, 100
line_to 0, 100
curve_to [150, 250], :bounds => [[20, 200], [120, 200]]
curve_to [200, 0], :bounds => [[150, 200], [450, 10]]
end
 
fill_ellipse [200, 100], 100, 50
 
start_new_page
 
text "On the new page", align: :center, size: 8.mm
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.