Skip to content

Instantly share code, notes, and snippets.

@leeky
Forked from kevinprince/gist:1212725
Created September 12, 2011 23:23
Show Gist options
  • Save leeky/1212750 to your computer and use it in GitHub Desktop.
Save leeky/1212750 to your computer and use it in GitHub Desktop.
badges in ruby
# Requires the following gems: prawn, barby and rqrcode
require "prawn"
require "prawn/measurement_extensions"
require "barby"
require "barby/barcode/code_128"
require "barby/outputter/prawn_outputter"
barcode = Barby::Code128.new('12345','A')
badge = Prawn::Document.new(:page_size => "A5", :page_layout => :landscape, :margin => 0) do |pdf|
pdf.bounding_box [0.mm, 148.mm], :width => 105.mm, :height => 148.mm do
pdf.bounding_box [5.mm, 105.mm], :width => 105.mm, :height => 220.mm do
pdf.font("Helvetica", :size => 36) do
pdf.text "Jonathon", :style => :bold
pdf.text "Doedeer", :style => :bold
end
pdf.font("Helvetica", :size => 16) do
pdf.text "@jdoe"
end
end
pdf.bounding_box [5.mm, pdf.bounds.bottom + 50.mm], :width => 95.mm, :height => 30.mm do
barcode.annotate_pdf(pdf, :xdim => 2, :height => 20.mm)
end
end
pdf.bounding_box [105.mm, 148.mm], :width => 105.mm, :height => 148.mm do
pdf.bounding_box [5.mm, 105.mm], :width => 105.mm, :height => 220.mm do
pdf.font("Helvetica", :size => 36) do
pdf.text "Jonathon", :style => :bold
pdf.text "Doedeer", :style => :bold
end
pdf.font("Helvetica", :size => 16) do
pdf.text "@jdoe"
end
end
pdf.bounding_box [5.mm, pdf.bounds.bottom + 50.mm], :width => 95.mm, :height => 30.mm do
barcode.annotate_pdf(pdf, :xdim => 2, :height => 20.mm)
end
end
end
# Return document as data (can be rendered directly on a browser without saving first!)
puts badge.render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment