Class: Tabula::Extraction::PagesInfoExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/tabula/extraction.rb

Instance Method Summary collapse

Constructor Details

#initialize(pdf_filename, password = '') ⇒ PagesInfoExtractor

Returns a new instance of PagesInfoExtractor.



374
375
376
377
378
# File 'lib/tabula/extraction.rb', line 374

def initialize(pdf_filename, password='')
  @pdf_filename = pdf_filename
  @pdf_file = Extraction.openPDF(pdf_filename, password)
  @all_pages = @pdf_file.getDocumentCatalog.getAllPages
end

Instance Method Details

#pagesObject



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'lib/tabula/extraction.rb', line 380

def pages
  Enumerator.new do |y|
    begin
      @all_pages.each_with_index do |page, i|
        contents = page.getContents

        y.yield Tabula::Page.new(@pdf_filename,
                                 page.findCropBox.width,
                                 page.findCropBox.height,
                                 page.getRotation.to_i,
                                 i+1) #remember, these are one-indexed
      end
    ensure
      @pdf_file.close
    end
  end
end