Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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