Class: Grim::Pdf
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Creates an instance Grim::Page for the index passed in.
-
#count ⇒ Object
Shells out to ghostscript to read the pdf with the pdf_info.ps script as a filter, returning the number of pages in the pdf as an integer.
- #each ⇒ Object
-
#initialize(path, options = {}) ⇒ Pdf
constructor
Raises an error if pdf not found and sets some instance variables if pdf is found.
Constructor Details
#initialize(path, options = {}) ⇒ Pdf
Raises an error if pdf not found and sets some instance variables if pdf is found.
path - A String or Path to the pdf options - A Hash of options.
:pdftotext_path - The String path of where to find the pdftotext
binary to use when extracting text
(default: "pdftotext").
17 18 19 20 21 |
# File 'lib/grim/pdf.rb', line 17 def initialize(path, = {}) raise Grim::PdfNotFound unless File.exist?(path) @path = path @pdftotext_path = [:pdftotext_path] || 'pdftotext' end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/grim/pdf.rb', line 6 def path @path end |
Instance Method Details
#[](index) ⇒ Object
Creates an instance Grim::Page for the index passed in.
index - accepts Integer for position in array
For example:
pdf[4] # returns 5th page
Returns an instance of Grim::Page.
49 50 51 52 |
# File 'lib/grim/pdf.rb', line 49 def [](index) raise Grim::PageNotFound unless index >= 0 && index < count Grim::Page.new(self, index, pdftotext_path: @pdftotext_path) end |
#count ⇒ Object
Shells out to ghostscript to read the pdf with the pdf_info.ps script as a filter, returning the number of pages in the pdf as an integer.
For example:
pdf.count
# => 4
Returns an Integer.
33 34 35 36 37 |
# File 'lib/grim/pdf.rb', line 33 def count @count ||= begin Grim.processor.count(@path) end end |