Class: PdfUtils::Info

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf_utils/info.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ Info

Returns a new instance of Info.

Raises:

  • (ArgumentError)


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

#authorObject (readonly)

Returns the value of attribute author.



3
4
5
# File 'lib/pdf_utils/info.rb', line 3

def author
  @author
end

#creation_dateObject (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

#creatorObject (readonly)

Returns the value of attribute creator.



3
4
5
# File 'lib/pdf_utils/info.rb', line 3

def creator
  @creator
end

#encryptedObject (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_sizeObject (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

#keywordsObject (readonly)

Returns the value of attribute keywords.



3
4
5
# File 'lib/pdf_utils/info.rb', line 3

def keywords
  @keywords
end

#mod_dateObject (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

#optimizedObject (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_formatObject (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_sizeObject (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

#pagesObject (readonly)

Returns the value of attribute pages.



4
5
6
# File 'lib/pdf_utils/info.rb', line 4

def pages
  @pages
end

#pdf_versionObject (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

#producerObject (readonly)

Returns the value of attribute producer.



3
4
5
# File 'lib/pdf_utils/info.rb', line 3

def producer
  @producer
end

#subjectObject (readonly)

Returns the value of attribute subject.



3
4
5
# File 'lib/pdf_utils/info.rb', line 3

def subject
  @subject
end

#taggedObject (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

#titleObject (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_dimensionsObject



34
35
36
# File 'lib/pdf_utils/info.rb', line 34

def page_dimensions
  [page_width, page_height]
end

#page_heightObject



42
43
44
# File 'lib/pdf_utils/info.rb', line 42

def page_height
  @page_size[1]
end

#page_widthObject



38
39
40
# File 'lib/pdf_utils/info.rb', line 38

def page_width
  @page_size[0]
end