2012-02-27 4 views

답변

7

pdf-reader 보석은 이것을 할 수 있습니다.

require 'pdf/reader' 
require 'bigdecimal' 

def pt2mm(pt) 
    (pt2in(pt) * BigDecimal.new("25.4")).round(2) 
end 

def pt2in(pt) 
    (pt/BigDecimal.new("72")).round(2) 
end 

reader = PDF::Reader.new("somefile.pdf") 
reader.pages.each do |page| 
    bbox = page.attributes[:MediaBox] 
    width = bbox[2] - bbox[0] 
    height = bbox[3] - bbox[1] 

    puts "width: #{width}pts #{pt2mm(width).to_s("F")}mm #{pt2in(width).to_s("F")}in" 
    puts "height: #{height}pts #{pt2mm(height).to_s("F")}mm #{pt2in(height).to_s("F")}in" 
end 
+0

'MediaBox' 속성을 무시하기 때문에 일부 문서에 포함 된'CropBox' 속성을 확인하는 것이 좋습니다. –

관련 문제