├── Champignon.ttf ├── certificate.png ├── sample └── Jason Long-GitHub & Git Foundations.pdf ├── README.md └── training-cert.rb /Champignon.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jasonlong/training-cert-generator/master/Champignon.ttf -------------------------------------------------------------------------------- /certificate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jasonlong/training-cert-generator/master/certificate.png -------------------------------------------------------------------------------- /sample/Jason Long-GitHub & Git Foundations.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jasonlong/training-cert-generator/master/sample/Jason Long-GitHub & Git Foundations.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Command line tool for generating PDF training certificates. 2 | 3 | Requirements 4 | ============ 5 | 6 | [Prawn](http://prawn.majesticseacreature.com/) for PDF generation 7 | `gem install prawn` 8 | 9 | [Trollop](http://trollop.rubyforge.org/) for command line parsing 10 | `gem install trollop` 11 | 12 | Usage 13 | ===== 14 | ``` 15 | ruby training-cert [options] 16 | where [options] are: 17 | --recipient, -r : Recipient's name (required) 18 | --company, -c : Recipient's company name (optional) 19 | --course, -o : Course name (required) 20 | --date, -d : Date (required) 21 | --instructor, -i : Instructor (required) 22 | --help, -h: Show this message 23 | ``` 24 | 25 | -------------------------------------------------------------------------------- /training-cert.rb: -------------------------------------------------------------------------------- 1 | require 'prawn' 2 | require 'trollop' 3 | 4 | # command line options 5 | opts = Trollop::options do 6 | banner <<-EOS 7 | This generates a GitHub training certificate in PDF format. 8 | 9 | Usage: 10 | ruby training-cert [options] 11 | where [options] are: 12 | EOS 13 | 14 | opt :recipient, "Recipient's name (required)", :type => String 15 | opt :company, "Recipient's company name (optional)", :type => String 16 | opt :course, "Course name (required)", :type => String 17 | opt :date, "Date (required)", :type => String 18 | opt :instructor, "Instructor (required)", :type => String 19 | end 20 | Trollop::die :recipient, "must be specified" if !opts[:recipient] 21 | Trollop::die :course, "must be specified" if !opts[:course] 22 | Trollop::die :date, "must be specified" if !opts[:date] 23 | Trollop::die :instructor, "must be specified" if !opts[:instructor] 24 | 25 | pdf = Prawn::Document.new(:margin => 1, :page_layout => :landscape) 26 | pdf.font_families.update("Champignon" => { 27 | :normal => "Champignon.ttf" 28 | }) 29 | 30 | # background certificate image 31 | pdf.image "certificate.png", 32 | :position => :center, 33 | :vposition => :center, 34 | :scale => 0.23, 35 | :fit => [Prawn::Document::PageGeometry::SIZES["LETTER"][1], 36 | Prawn::Document::PageGeometry::SIZES["LETTER"][0]] 37 | 38 | # intro 39 | pdf.bounding_box([240, 410], :width => 320, :height => 50) do 40 | pdf.fill_color "00a5ea" 41 | pdf.font("Champignon") do 42 | pdf.text "This certifies that", :size => 32, :align => :center, :valign => :top 43 | end 44 | end 45 | 46 | # recipient name 47 | pdf.bounding_box([240, 367], :width => 320, :height => 30) do 48 | pdf.fill_color "111111" 49 | pdf.font("Times-Roman") do 50 | pdf.text opts[:recipient].upcase, :size => 22, :style => :bold, :align => :center, :valign => :bottom 51 | end 52 | end 53 | 54 | # recipient company name (optional) 55 | unless opts[:company].nil? 56 | pdf.bounding_box([240, 345], :width => 320, :height => 30) do 57 | pdf.fill_color "111111" 58 | pdf.font("Times-Roman") do 59 | pdf.text opts[:company], :size => 12, :align => :center, :valign => :bottom 60 | end 61 | end 62 | end 63 | 64 | # requirements blurb 65 | pdf.bounding_box([140, 310], :width => 520, :height => 50) do 66 | pdf.fill_color "00a5ea" 67 | pdf.font("Champignon") do 68 | pdf.text "has completed the training program requirements for", :size => 32, :leading => 3, :align => :center, :valign => :top 69 | end 70 | end 71 | 72 | # course name 73 | pdf.bounding_box([140, 270], :width => 520, :height => 30) do 74 | pdf.fill_color "111111" 75 | pdf.font("Times-Roman") do 76 | pdf.text opts[:course].upcase, :size => 22, :style => :bold, :align => :center, :valign => :bottom 77 | end 78 | end 79 | 80 | # date 81 | pdf.bounding_box([152, 200], :width => 180, :height => 30) do 82 | pdf.fill_color "111111" 83 | pdf.font("Times-Roman") do 84 | pdf.text opts[:date], :size => 12, :valign => :bottom 85 | end 86 | end 87 | 88 | # date label 89 | pdf.bounding_box([152, 182], :width => 180, :height => 30) do 90 | pdf.fill_color "00a5ea" 91 | pdf.font("Times-Roman") do 92 | pdf.text "DATE", :size => 10, :valign => :bottom 93 | end 94 | end 95 | 96 | # instructor 97 | pdf.bounding_box([462, 200], :width => 180, :height => 30) do 98 | pdf.fill_color "111111" 99 | pdf.font("Times-Roman") do 100 | pdf.text opts[:instructor], :size => 12, :valign => :bottom 101 | end 102 | end 103 | 104 | # instructor label 105 | pdf.bounding_box([462, 182], :width => 180, :height => 30) do 106 | pdf.fill_color "00a5ea" 107 | pdf.font("Times-Roman") do 108 | pdf.text "INSTRUCTOR", :size => 10, :valign => :bottom 109 | end 110 | end 111 | 112 | pdf.render_file "#{opts[:recipient]}-#{opts[:course]}.pdf" 113 | --------------------------------------------------------------------------------