Class: Rabbit::Parser::PDF

Inherits:
Base
  • Object
show all
Includes:
Element
Defined in:
lib/rabbit/parser/pdf.rb

Constant Summary

Constants included from ModuleLoader

ModuleLoader::LOADERS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, name

Methods included from ModuleLoader

extend_object, #find_loader, #loaders, #push_loader, #unshift_loader

Constructor Details

This class inherits a constructor from Rabbit::Parser::Base

Class Method Details

.match?(source) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rabbit/parser/pdf.rb', line 13

def match?(source)
  source.read.start_with?("%PDF-1.")
end

Instance Method Details

#parseObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rabbit/parser/pdf.rb', line 19

def parse
  @pdf = Tempfile.new("rabbit-pdf")
  @pdf.binmode
  @pdf.print(@source.read)
  @pdf.close
  doc = Poppler::Document.new("file://#{@pdf.path}")

  title_page, *rest = doc.to_a

  @canvas << PopplerTitleSlide.new(title_page, doc)
  rest.each do |page|
    @canvas << PopplerSlide.new(page)
  end
end