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.2.0"
@@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:

  • cmd (String)

    The command to run

Returns:

  • (String)

    The output of the command



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

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:

  • filename (String)

    The filename of the PDF to open

Returns:

  • (Array)

    An array of images



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

def open(filename, &block)
    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