Class: PdfUtils::Info
- Inherits:
-
Object
- Object
- PdfUtils::Info
- Defined in:
- lib/pdf_utils/info.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#creation_date ⇒ Object
readonly
Returns the value of attribute creation_date.
-
#creator ⇒ Object
readonly
Returns the value of attribute creator.
-
#encrypted ⇒ Object
(also: #encrypted?)
readonly
Returns the value of attribute encrypted.
-
#file_size ⇒ Object
readonly
Returns the value of attribute file_size.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#mod_date ⇒ Object
(also: #modification_date)
readonly
Returns the value of attribute mod_date.
-
#optimized ⇒ Object
(also: #optimized?)
readonly
Returns the value of attribute optimized.
-
#page_format ⇒ Object
readonly
Returns the value of attribute page_format.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
-
#pages ⇒ Object
readonly
Returns the value of attribute pages.
-
#pdf_version ⇒ Object
readonly
Returns the value of attribute pdf_version.
-
#producer ⇒ Object
readonly
Returns the value of attribute producer.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#tagged ⇒ Object
(also: #tagged?)
readonly
Returns the value of attribute tagged.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(filename) ⇒ Info
constructor
A new instance of Info.
- #page_dimensions ⇒ Object
- #page_height ⇒ Object
- #page_width ⇒ Object
Constructor Details
#initialize(filename) ⇒ Info
Returns a new instance of Info.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/pdf_utils/info.rb', line 10 def initialize(filename) raise ArgumentError.new("File does not exist: #{filename}") unless File.exist?(filename) info = {} PdfUtils::run_command(:pdfinfo, filename).scan(/^([^:]+): +(.*?)?$/) do |property| info.store(*property) end @pdf_version = info["PDF version"] @title = info["Title"] @subject = info["Subject"] @keywords = info["Keywords"] @author = info["Author"] @creator = info["Creator"] @producer = info["Producer"] @pages = info["Pages"].to_i @creation_date = Time.parse(info["CreationDate"]) rescue nil @mod_date = Time.parse(info["ModDate"]) rescue nil @page_size = info["Page size"] =~ /^([\d.]+) x ([\d.]+)/ && [$1.to_f, $2.to_f] @page_format = info["Page size"] =~ /\(([^(]+)\)$/ && $1 @file_size = info["File size"] =~ /^(\d+) bytes$/ && $1.to_i @optimized = info["Optimized"] == 'yes' @tagged = info["Tagged"] == 'yes' @encrypted = info["Encrypted"] == 'yes' end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
3 4 5 |
# File 'lib/pdf_utils/info.rb', line 3 def @author end |
#creation_date ⇒ Object (readonly)
Returns the value of attribute creation_date.
4 5 6 |
# File 'lib/pdf_utils/info.rb', line 4 def creation_date @creation_date end |
#creator ⇒ Object (readonly)
Returns the value of attribute creator.
3 4 5 |
# File 'lib/pdf_utils/info.rb', line 3 def creator @creator end |
#encrypted ⇒ Object (readonly) Also known as: encrypted?
Returns the value of attribute encrypted.
3 4 5 |
# File 'lib/pdf_utils/info.rb', line 3 def encrypted @encrypted end |
#file_size ⇒ Object (readonly)
Returns the value of attribute file_size.
4 5 6 |
# File 'lib/pdf_utils/info.rb', line 4 def file_size @file_size end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
3 4 5 |
# File 'lib/pdf_utils/info.rb', line 3 def keywords @keywords end |
#mod_date ⇒ Object (readonly) Also known as: modification_date
Returns the value of attribute mod_date.
4 5 6 |
# File 'lib/pdf_utils/info.rb', line 4 def mod_date @mod_date end |
#optimized ⇒ Object (readonly) Also known as: optimized?
Returns the value of attribute optimized.
3 4 5 |
# File 'lib/pdf_utils/info.rb', line 3 def optimized @optimized end |
#page_format ⇒ Object (readonly)
Returns the value of attribute page_format.
4 5 6 |
# File 'lib/pdf_utils/info.rb', line 4 def page_format @page_format end |
#page_size ⇒ Object (readonly)
Returns the value of attribute page_size.
4 5 6 |
# File 'lib/pdf_utils/info.rb', line 4 def page_size @page_size end |
#pages ⇒ Object (readonly)
Returns the value of attribute pages.
4 5 6 |
# File 'lib/pdf_utils/info.rb', line 4 def pages @pages end |
#pdf_version ⇒ Object (readonly)
Returns the value of attribute pdf_version.
3 4 5 |
# File 'lib/pdf_utils/info.rb', line 3 def pdf_version @pdf_version end |
#producer ⇒ Object (readonly)
Returns the value of attribute producer.
3 4 5 |
# File 'lib/pdf_utils/info.rb', line 3 def producer @producer end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
3 4 5 |
# File 'lib/pdf_utils/info.rb', line 3 def subject @subject end |
#tagged ⇒ Object (readonly) Also known as: tagged?
Returns the value of attribute tagged.
3 4 5 |
# File 'lib/pdf_utils/info.rb', line 3 def tagged @tagged end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/pdf_utils/info.rb', line 3 def title @title end |
Instance Method Details
#page_dimensions ⇒ Object
34 35 36 |
# File 'lib/pdf_utils/info.rb', line 34 def page_dimensions [page_width, page_height] end |
#page_height ⇒ Object
42 43 44 |
# File 'lib/pdf_utils/info.rb', line 42 def page_height @page_size[1] end |
#page_width ⇒ Object
38 39 40 |
# File 'lib/pdf_utils/info.rb', line 38 def page_width @page_size[0] end |