Skip to content

Instantly share code, notes, and snippets.

@iorionda
Created July 4, 2013 11:42
Show Gist options
  • Select an option

  • Save iorionda/5926999 to your computer and use it in GitHub Desktop.

Select an option

Save iorionda/5926999 to your computer and use it in GitHub Desktop.
require 'pdf/reader'
require 'bigdecimal'
def pt2mm(pt)
(pt2inch(pt) * BigDecimal.new("25.4")).round(2)
end
def pt2inch(pt)
(pt / BigDecimal.new("72")).round(2)
end
reader = PDF::Reader.new(ARGV[0])
reader.pages.each do |page|
mediabox = page.page_object[:MediaBox]
width = mediabox[2] - mediabox[0]
height = mediabox[3] - mediabox[1]
puts "Width : #{width}pts #{pt2mm(width).to_s}mm #{pt2inch(width).to_s}inch"
puts "Height: #{height}pts #{pt2mm(height).to_s}mm #{pt2inch(height).to_s}inch"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment