Skip to content

Instantly share code, notes, and snippets.

@bradediger
Created February 5, 2009 18:17
Show Gist options
  • Save bradediger/58890 to your computer and use it in GitHub Desktop.
Save bradediger/58890 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
require 'prawn'
CHECKBOX = "\xE2\x98\x90" # "☐"
FILLED_CHECKBOX = "\xE2\x98\x91" # "☑"
Prawn::Document.generate("checkbox_test.pdf") do
# Use a font with the checkbox characters:
# http://www.fileformat.info/info/unicode/char/2610/fontsupport.htm
font "fonts/dejavu/ttf/DejaVuSans.ttf"
text "#{CHECKBOX} Not done yet"
text "#{FILLED_CHECKBOX} Complete!"
end
@henrik
Copy link

henrik commented Feb 11, 2013

Also, you can use formatted_text so the label is in your default font:

EMPTY_CHECKBOX   = "\u2610" # "☐"
CHECKED_CHECKBOX = "\u2611" # "☑"  I don't use this, but you could.
EXED_CHECKBOX    = "\u2612" # "☒"
CHECKBOX_FONT    = "#{Prawn::BASEDIR}/data/fonts/DejaVuSans.ttf"

def checkbox(label, checked)
  box = checked ? EXED_CHECKBOX : EMPTY_CHECKBOX

  formatted_text [
    { text: box, font: CHECKBOX_FONT },
    { text: " #{label}" }
  ]
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment