Class: Stevedore::Pdf::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/stevedore/pdf.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, page_number) ⇒ Image

Returns a new instance of Image.



69
70
71
72
# File 'lib/stevedore/pdf.rb', line 69

def initialize(file_path, page_number)
  @file_path = file_path
  @page_number = page_number
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



52
53
54
# File 'lib/stevedore/pdf.rb', line 52

def file_path
  @file_path
end

#page_numberObject (readonly)

Returns the value of attribute page_number.



52
53
54
# File 'lib/stevedore/pdf.rb', line 52

def page_number
  @page_number
end

Class Method Details

.extract_all(pdf, base_dir) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/stevedore/pdf.rb', line 54

def self.extract_all(pdf, base_dir)
  @pdf = pdf
  images = []
  (1..pdf.num_pages).each do |page_number|
    base_name = "#{base_dir}/page-#{sprintf("%00d", page_number)}"
    Stevedore.run("pdfimages -f #{page_number} -l #{page_number} #{@pdf.file_path} #{base_name}")

    Dir.glob("#{base_name}*").sort.each do |file_path|
      images << new(file_path, page_number)
    end
  end

  images
end