Class: ActiveBlob::Blob::PDF
Instance Attribute Summary
#data
Class Method Summary
collapse
Instance Method Summary
collapse
#extension, #file, #file=, new, #open, #url, #url=
#file_content_type, #file_sha1, filename_from_file
Class Method Details
.process(record, path) ⇒ Object
21
22
23
24
25
26
27
28
29
|
# File 'app/models/activeblob/blob/pdf.rb', line 21
def self.process(record, path)
require 'pdf-reader' unless defined?(PDF::Reader)
record.metadata = {
'pages' => PDF::Reader.new(path).pages.map { |page|
{ 'width' => page.width, 'height' => page.height }
}
}
end
|
Instance Method Details
#aspect_ratio ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'app/models/activeblob/blob/pdf.rb', line 9
def aspect_ratio
first_page = metadata['pages']&.first
return nil unless first_page
width = first_page['width'].to_f
height = first_page['height'].to_f
return nil if height.zero?
width / height
end
|
#page_count ⇒ Object
5
6
7
|
# File 'app/models/activeblob/blob/pdf.rb', line 5
def page_count
metadata['pages']&.size || 0
end
|