Skip to content

Instantly share code, notes, and snippets.

@rexikan
Created April 17, 2013 07:08
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 rexikan/5402339 to your computer and use it in GitHub Desktop.
Save rexikan/5402339 to your computer and use it in GitHub Desktop.
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
source 'https://rubygems.org'
gem 'prawn'
gem 'rb-fsevent', '~> 0.9'
gem 'guard'
gem 'guard-shell'
guard :shell do
watch(/(.*).rb/) do |m|
`ruby #{m[0]} && open #{m[1]}.pdf`
end
end
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment