class Rabbit::ImageManipulable::PDF
Public Class Methods
match?(filename)
click to toggle source
# File lib/rabbit/image/pdf.rb, line 16 def match?(filename) return true if File.extname(filename) == ".pdf" File.open(filename) do |file| line = file.gets return false if line.nil? begin /\A%PDF-1\.\d\z/ =~ line.chomp rescue ArgumentError false end 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 32 def draw(canvas, x, y, params={}) if @document default_params = { :width => width, :height => height, } 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 44 def pixbuf @pixbuf ||= to_pixbuf end
Private Instance Methods
filename()
click to toggle source
# File lib/rabbit/image/pdf.rb, line 70 def filename File.expand_path(@filename) end
page()
click to toggle source
# File lib/rabbit/image/pdf.rb, line 49 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 78 def to_pixbuf w = original_width h = original_height pixbuf = Gdk::Pixbuf.new(Gdk::Pixbuf::COLORSPACE_RGB, true, 8, w, h) page.render(0, 0, w, h, 1.0, 0, pixbuf) pixbuf end
update_size()
click to toggle source
# File lib/rabbit/image/pdf.rb, line 65 def update_size @document = Poppler::Document.new(uri) @width, @height = page.size end
uri()
click to toggle source
# File lib/rabbit/image/pdf.rb, line 74 def uri "file://#{filename}" end