class PDF::Reader::OrientationDetector
Small util class for detecting the orientation of a single PDF page. Accounts for any page rotation that is in place.
OrientationDetector.new(:MediaBox => [0,0,612,792]).orientation => "portrait"
Public Class Methods
new(attributes)
click to toggle source
# File lib/pdf/reader/orientation_detector.rb, line 10 def initialize(attributes) @attributes = attributes end
Public Instance Methods
orientation()
click to toggle source
# File lib/pdf/reader/orientation_detector.rb, line 14 def orientation @orientation ||= detect_orientation end
Private Instance Methods
detect_orientation()
click to toggle source
# File lib/pdf/reader/orientation_detector.rb, line 20 def detect_orientation llx,lly,urx,ury = @attributes[:MediaBox] rotation = @attributes[:Rotate].to_i width = urx.to_i - llx.to_i height = ury.to_i - lly.to_i if width > height [0,180].include?(rotation) ? 'landscape' : 'portrait' else [0,180].include?(rotation) ? 'portrait' : 'landscape' end end