Class: PdfParadise::PdfStatistics

Inherits:
Base
  • Object
show all
Defined in:
lib/pdf_paradise/utility_scripts/pdf_statistics.rb

Overview

PdfParadise::PdfStatistics

Constant Summary

Constants inherited from Base

Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#basename, #be_verbose?, #change_directory, #commandline_arguments?, #copy_file, #delete_file, #e, #ecomment, #esystem, #first_argument?, #gold, #infer_the_namespace, #input_without_leading_hyphens?, #internal_hash?, #is_an_image_file?, #is_on_roebe?, #lightsteelblue, #log_dir?, #mkdir, #mv, #n_pages?, #namespace?, #no_file_at, #opne, #opnn, #orange, #reset_the_internal_hash, #return_commandline_arguments_starting_with_hyphens, #return_files_from_the_commandline_arguments, #return_pwd, #rev, #set_be_quiet, #set_commandline_arguments, #steelblue, #try_to_ensure_that_this_directory_exists, #write_what_into

Constructor Details

#initialize(i = nil, run_already = true) ⇒ PdfStatistics

#

initialize

#


39
40
41
42
43
44
45
46
47
# File 'lib/pdf_paradise/utility_scripts/pdf_statistics.rb', line 39

def initialize(
    i           = nil,
    run_already = true
  )
  require_pdf_reader
  reset
  set_input(i)
  run if run_already
end

Class Method Details

.[](i = '') ⇒ Object

#

PdfParadise::PdfStatistics[]

#


140
141
142
# File 'lib/pdf_paradise/utility_scripts/pdf_statistics.rb', line 140

def self.[](i = '')
  new(i)
end

Instance Method Details

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


77
78
79
# File 'lib/pdf_paradise/utility_scripts/pdf_statistics.rb', line 77

def input?
  @input
end

#instantiate_reader_objectObject

#

instantiate_reader_object

#


84
85
86
# File 'lib/pdf_paradise/utility_scripts/pdf_statistics.rb', line 84

def instantiate_reader_object
  @reader = PDF::Reader.new(input?)
end

#report_n_pages_in_the_pdf_documentObject

#

report_n_pages_in_the_pdf_document

#


119
120
121
# File 'lib/pdf_paradise/utility_scripts/pdf_statistics.rb', line 119

def report_n_pages_in_the_pdf_document
  e 'n pages in this .pdf document:  '+simp(@reader.page_count)
end

#require_pdf_readerObject

#

require_pdf_reader

#


58
59
60
61
62
63
# File 'lib/pdf_paradise/utility_scripts/pdf_statistics.rb', line 58

def require_pdf_reader
  old_verbose = $VERBOSE
  $VERBOSE = nil
  require 'pdf-reader'
  $VERBOSE = old_verbose # Restore it again here.
end

#resetObject

#

reset (reset tag)

#


52
53
# File 'lib/pdf_paradise/utility_scripts/pdf_statistics.rb', line 52

def reset
end

#runObject

#

run (run tag)

#


126
127
128
129
130
131
132
133
134
135
# File 'lib/pdf_paradise/utility_scripts/pdf_statistics.rb', line 126

def run
  instantiate_reader_object
  cliner
  e rev+
    'The PDF version for this .pdf file was: '+simp(@reader.pdf_version)
  show_extended_info
  # e @reader.metadata # <- This is how to obtain the metadata information.
  report_n_pages_in_the_pdf_document
  cliner
end

#set_input(i = '') ⇒ Object

#

set_input

#


68
69
70
71
72
# File 'lib/pdf_paradise/utility_scripts/pdf_statistics.rb', line 68

def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @input = i
end

#show_extended_infoObject

#

show_extended_info

This will tap into the .info method.

#


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/pdf_paradise/utility_scripts/pdf_statistics.rb', line 93

def show_extended_info
  hash = @reader.info
  ljust = 32
  if hash.has_key? :Title
    e 'The title of this .pdf is: '.ljust(ljust)+simp(hash[:Title])
  end
  if hash.has_key? :CreationDate
    e 'This .pdf was created at: '.ljust(ljust)+simp(hash[:CreationDate])
  end
  if hash.has_key? :Author
    e 'The author of this .pdf is: '.ljust(ljust)+simp(hash[:Author])
  end
  if hash.has_key? :Producer
    e 'It was produced via: '.ljust(ljust)+simp(hash[:Producer])
  end
  if hash.has_key? :ModDate
    e 'It was last modified at: '.ljust(ljust)+simp(hash[:ModDate])
  end
  if hash.has_key? :Creator
    e 'It was created via: '.ljust(ljust)+simp(hash[:Creator])
  end
end