Created
          April 15, 2011 00:41 
        
      - 
      
- 
        Save fnando/920904 to your computer and use it in GitHub Desktop. 
    Create PDF using Prawn
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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