Class: Pdftotext::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/pdftotext/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Document



5
6
7
# File 'lib/pdftotext/document.rb', line 5

def initialize(path)
  @path = File.expand_path(path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/pdftotext/document.rb', line 3

def path
  @path
end

Instance Method Details

#pages(options = {}) ⇒ Object



16
17
18
19
# File 'lib/pdftotext/document.rb', line 16

def pages(options={})
  pages = text(options).split("\f")
  pages.each_with_index.map { |t,i| Page.new text: t, number: i+1 }
end

#text(options = {}) ⇒ Object



9
10
11
12
13
14
# File 'lib/pdftotext/document.rb', line 9

def text(options={})
  Pdftotext.cli.run_command path, tempfile.path, options
  text = tempfile.read
  tempfile.close!
  text
end