class Rabbit::ImageManipulable::PDF

Public Class Methods

match?(filename) click to toggle source
# File lib/rabbit/image/pdf.rb, line 30
def match?(filename)
  return true if File.extname(filename) == ".pdf"

  File.open(filename, "rb") do |file|
    data = file.read(10)
    return false if data.nil?

    data.start_with?("%PDF-1.")
  end
end

Public Instance Methods

draw(canvas, x, y, params={}) click to toggle source
Calls superclass method Rabbit::ImageManipulable::Base#draw
# File lib/rabbit/image/pdf.rb, line 42
def draw(canvas, x, y, params={})
  if @document
    default_params = default_draw_params(x, y)
    canvas.draw_poppler_page(page, x, y, default_params.merge(params))
  else
    super
  end
end
pixbuf() click to toggle source
# File lib/rabbit/image/pdf.rb, line 51
def pixbuf
  @pixbuf ||= to_pixbuf
end
update_size() click to toggle source
# File lib/rabbit/image/pdf.rb, line 55
def update_size
  @document = Poppler::Document.new(uri)
  @width, @height = page.size
end

Private Instance Methods

filename() click to toggle source
# File lib/rabbit/image/pdf.rb, line 77
def filename
  File.expand_path(@filename)
end
page() click to toggle source
# File lib/rabbit/image/pdf.rb, line 61
def page
  index = self["page"] || 1
  begin
    index = Integer(index)
  rescue ArgumentError
    message = _("invalid PDF page number: <%s>") % index.inspect
    raise ImageLoadError.new("#{@filename}: #{message}")
  end
  _page = @document[index - 1]
  if _page.nil?
    message = _("%s page doesn't exist in PDF") % index
    raise ImageLoadError.new("#{@filename}: #{message}")
  end
  _page
end
to_pixbuf() click to toggle source
# File lib/rabbit/image/pdf.rb, line 85
def to_pixbuf
  w = original_width
  h = original_height
  pixbuf = GdkPixbuf::Pixbuf.new(:rgb, true, 8, w, h)
  page.render(0, 0, w, h, 1.0, 0, pixbuf)
  pixbuf
end
uri() click to toggle source
# File lib/rabbit/image/pdf.rb, line 81
def uri
  GLib.filename_to_uri(filename)
end