Class: Grim::Page
- Inherits:
-
Object
- Object
- Grim::Page
- Defined in:
- lib/grim/page.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
Instance Method Summary collapse
-
#initialize(pdf, index, options = {}) ⇒ Page
constructor
Sets up some instance variables on new instance.
-
#save(path, options = {}) ⇒ Object
Extracts the selected page and turns it into an image.
-
#text ⇒ Object
Extracts the text from the selected page.
Constructor Details
#initialize(pdf, index, options = {}) ⇒ Page
Sets up some instance variables on new instance.
pdf - the pdf this page belongs to index - the index of the page in the array of pages options - A Hash of options.
:pdftotext_path - The String path of where to find the pdftotext
binary to use when extracting text
(default: "pdftotext").
16 17 18 19 20 21 |
# File 'lib/grim/page.rb', line 16 def initialize(pdf, index, = {}) @pdf = pdf @index = index @number = index + 1 @pdftotext_path = [:pdftotext_path] || 'pdftotext' end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
5 6 7 |
# File 'lib/grim/page.rb', line 5 def number @number end |
Instance Method Details
#save(path, options = {}) ⇒ Object
Extracts the selected page and turns it into an image. Tested on png and jpeg.
path - String of the path to save to options - Hash of options to customize the saving of the image
(ie: width, density, and quality)
For example:
pdf[1].save(/path/to/save/image.png)
# => true
Returns a File.
37 38 39 40 41 |
# File 'lib/grim/page.rb', line 37 def save(path, ={}) raise PathMissing if path.nil? || path !~ /\S/ Grim.processor.save(@pdf, @index, path, ) end |
#text ⇒ Object
Extracts the text from the selected page.
For example:
pdf[1].text
# => "This is text from slide 2.\n\nAnd even more text from slide 2."
Returns a String.
52 53 54 55 56 57 |
# File 'lib/grim/page.rb', line 52 def text command = [@pdftotext_path, "-enc", "UTF-8", "-f", @number, "-l", @number, Shellwords.escape(@pdf.path), "-"].join(' ') Grim.logger.debug { "Running pdftotext command" } Grim.logger.debug { command } `#{command}` end |