Class: PDFToImage::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/pdftoimage/image.rb

Overview

A class which is instantiated by PDFToImage when a PDF document is opened.

Constant Summary collapse

CUSTOM_IMAGE_METHODS =

ImageMagick methods that we currently support.

[
    "resize",
    "quality"
]
PDF_IMAGE_METHODS =

pdftoppm methods that we currently support.

[
    "r",
    "rx",
    "ry"
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pdf_name, filename, page, page_size, page_count) ⇒ Image

Image constructor

Parameters:

  • pdf_name (String)

    The name of the PDF

  • filename (String)

    The name of the image for the specified page

  • page (Integer)

    The page number of the PDF

  • page_size (Hash)

    Hash containing width and height dimensions of the page

  • page_count (integer)

    The number of pages in the PDF



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pdftoimage/image.rb', line 53

def initialize(pdf_name, filename, page, page_size, page_count)
    @args = []
    @pdf_args = []

    @pdf_name = pdf_name
    @filename = filename
    @opened = false
    @width = page_size[:width]
    @height = page_size[:height]
    @page_count = page_count

    @page = page
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



12
13
14
# File 'lib/pdftoimage/image.rb', line 12

def args
  @args
end

#filenameObject (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/pdftoimage/image.rb', line 8

def filename
  @filename
end

#heightObject (readonly)

Returns the value of attribute height.



10
11
12
# File 'lib/pdftoimage/image.rb', line 10

def height
  @height
end

#openedObject (readonly)

Returns the value of attribute opened.



14
15
16
# File 'lib/pdftoimage/image.rb', line 14

def opened
  @opened
end

#pageObject (readonly)

Returns the value of attribute page.



11
12
13
# File 'lib/pdftoimage/image.rb', line 11

def page
  @page
end

#pdf_argsObject (readonly)

Returns the value of attribute pdf_args.



13
14
15
# File 'lib/pdftoimage/image.rb', line 13

def pdf_args
  @pdf_args
end

#pdf_nameObject (readonly)

Returns the value of attribute pdf_name.



7
8
9
# File 'lib/pdftoimage/image.rb', line 7

def pdf_name
  @pdf_name
end

#widthObject (readonly)

Returns the value of attribute width.



9
10
11
# File 'lib/pdftoimage/image.rb', line 9

def width
  @width
end

Instance Method Details

#<=>(img) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'lib/pdftoimage/image.rb', line 87

def <=>(img)
    if @page == img.page
        return 0
    elsif @page < img.page
        return -1
    else
        return 1
    end
end

#crop(x, y, w, h) ⇒ Object



81
82
83
84
85
# File 'lib/pdftoimage/image.rb', line 81

def crop(x, y, w, h)
    @pdf_args.push("-x #{x}", "-y #{y}", "-W #{w}", "-H #{h}")

    self
end

#save(outname) ⇒ Object

Saves the converted image to the specified location

Parameters:

  • outname (String)

    The output filename of the image



71
72
73
74
75
76
77
78
79
# File 'lib/pdftoimage/image.rb', line 71

def save(outname)
    if outname.respond_to?(:write)
        save_to_io(outname)
    else
        save_to_file(outname)
    end

    return true
end