Sha256: 6b3b7c87dda6b964098ef0c279239adaad9dd401606be6f816f87d67c48c048d

Contents?: true

Size: 769 Bytes

Versions: 12

Compression:

Stored size: 769 Bytes

Contents

require "tempfile"

require "poppler"

require "rabbit/element"
require "rabbit/parser/base"

module Rabbit
  module Parser
    class PDF < Base
      unshift_loader(self)
      class << self
        def match?(source)
          return true if /\Apdf\z/i =~ source.extension.to_s
          source.read.start_with?("%PDF-1.")
        end
      end

      include Element
      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
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rabbit-2.0.6 lib/rabbit/parser/pdf.rb
rabbit-2.0.5 lib/rabbit/parser/pdf.rb
rabbit-2.0.4 lib/rabbit/parser/pdf.rb
rabbit-2.0.3 lib/rabbit/parser/pdf.rb
rabbit-2.0.2 lib/rabbit/parser/pdf.rb
rabbit-2.0.1 lib/rabbit/parser/pdf.rb
rabbit-2.0.0 lib/rabbit/parser/pdf.rb
rabbit-1.0.9 lib/rabbit/parser/pdf.rb
rabbit-1.0.8 lib/rabbit/parser/pdf.rb
rabbit-1.0.7 lib/rabbit/parser/pdf.rb
rabbit-1.0.6 lib/rabbit/parser/pdf.rb
rabbit-1.0.5 lib/rabbit/parser/pdf.rb