Skip to content

Instantly share code, notes, and snippets.

@fnando
Created April 15, 2011 00:41
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fnando/920904 to your computer and use it in GitHub Desktop.
Save fnando/920904 to your computer and use it in GitHub Desktop.
Create PDF using Prawn
require "prawn"
class Certificate
attr_accessor :path
PDF_OPTIONS = {
:page_size => "A5",
:page_layout => :landscape,
# :background => "public/images/cert_bg.png",
:margin => [40, 75]
}
def initialize(path = nil)
@path = path
end
def pdf
Prawn::Document.new(PDF_OPTIONS) do |pdf|
pdf.fill_color "40464e"
pdf.text "Ruby Metaprogramming", :size => 40, :style => :bold, :align => :center
pdf.move_down 30
pdf.text "Certificado", :size => 24, :align => :center, :style => :bold
pdf.move_down 30
pdf.text "Certificamos que <b>Nando Vieira</b> participou...", :inline_format => true
pdf.move_down 15
pdf.text "São Paulo, #{Time.now.strftime("%d/%m/%Y")}."
pdf.move_down 30
# pdf.font Rails.root.join("fonts/custom.ttf")
pdf.text "howto", :size => 24
pdf.move_up 5
pdf.font "Helvetica"
pdf.text "http://howtocode.com.br", :size => 10
end
end
def save
pdf.render_file(path)
end
end
Certificate.new("/tmp/cert.pdf").save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment