Module: PDFToImage
- Defined in:
- lib/pdftoimage.rb,
lib/pdftoimage.rb,
lib/pdftoimage/image.rb,
lib/pdftoimage/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
pdftoimage version
"0.3.2"- @@pdf_temp_dir =
A class variable for storing the location of our temp folder
File.join(Dir.tmpdir())
Class Method Summary collapse
-
.exec(cmd, error = nil) ⇒ String
Executes the specified command, returning the output.
-
.from_blob(data, &block) ⇒ Array
Opens a PDF from raw binary data.
-
.open(source, &block) ⇒ Array
Opens a PDF document and prepares it for splitting into images.
Class Method Details
.exec(cmd, error = nil) ⇒ String
Executes the specified command, returning the output.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pdftoimage.rb', line 69 def exec(cmd, error = nil) output = `#{cmd}` if $? != 0 if error == nil raise PDFError, "Error executing command: #{cmd}" else raise PDFError, error end end return output end |
.from_blob(data, &block) ⇒ Array
Opens a PDF from raw binary data.
60 61 62 63 |
# File 'lib/pdftoimage.rb', line 60 def from_blob(data, &block) filename = write_to_tempfile(data) open(filename, &block) end |
.open(source, &block) ⇒ Array
Opens a PDF document and prepares it for splitting into images.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pdftoimage.rb', line 32 def open(source, &block) filename = resolve_source(source) if not File.exist?(filename) raise PDFError, "File '#{filename}' not found." end pages = page_count(filename) # Array of images images = [] 1.upto(pages) { |n| dimensions = page_size(filename, n) image = Image.new(filename, random_filename, n, dimensions, pages) images << image } images.each(&block) if block_given? return images end |