1. Technology
You can opt-out at any time. Please refer to our privacy policy for contact information.

Bonus: Working with Units


When you're talking about typesetting and layouts, you start getting into a lot of different units of measurement. There are em's and en's, centimeters, inches, points, etc. Prawn comes with a library for dealing with these, allowing you to easily use the units you're familiar with. For example, you can say things like 3.cm or 30.mm. Behind the scenes, all these units of measurement will be converted into PDF's native unit of measurement, the point. Since this feature extends the Numeric class, and that might not always be convenient, this feature needs an extra require.

#!/usr/bin/env ruby
require 'rubygems'
require 'prawn'
require 'prawn/measurement_extensions'

puts "10 mm is #{10.mm} points"
puts "3 cm is #{3.cm} points"
puts "1 inch is #{1.in} points"
  1. About.com
  2. Technology
  3. Ruby
  4. Gems
  5. Bonus: Working with Units

©2014 About.com. All rights reserved.