Module: PDFToImage

Defined in:
lib/pdftoimage.rb,
lib/pdftoimage.rb,
lib/pdftoimage/image.rb,
lib/pdftoimage/version.rb

Defined Under Namespace

Classes: Image, PDFError

Constant Summary collapse

VERSION =

pdftoimage version

"0.1.6"
@@pdf_temp_dir =

A class variable for storing the location of our temp folder

File.join(Dir.tmpdir())

Class Method Summary collapse

Class Method Details

.exec(cmd, error = nil) ⇒ String

Executes the specified command, returning the output.

Parameters:

  • The (cmd)

    command to run

Returns:

  • (String)

    The output of the command



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/pdftoimage.rb', line 60

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

.open(filename, &block) ⇒ Array

Opens a PDF document and prepares it for splitting into images.

Parameters:

  • The (filename)

    filename of the PDF to open

Returns:

  • (Array)

    An array of images



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/pdftoimage.rb', line 34

def open(filename, &block)
  if not File.exists?(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