Sha256: 35e1ff429f348ee395037562100f30d548e940db68a32b6fdf1d61e0cac85c3f

Contents?: true

Size: 1.08 KB

Versions: 27

Compression:

Stored size: 1.08 KB

Contents

module TaliaCore
  module DataTypes

    # Class to manage PDF data type
    class PdfData < FileRecord
     
      # return the mime_type for a file
      def extract_mime_type(location)
        'application/pdf'
      end

      # Create the PDF data from a PDF writer. This method needs a block
      # which will be called with the writer object
      def create_from_writer(writer_opts = {})
        activate_pdf
        writer = PDF::Writer.new(writer_opts) do |pdf|
          yield(pdf)
        end
        filename = File.join(Dir.tmpdir, "#{rand 10E16}.pdf")
        writer.save_as(filename)
        self.create_from_file('', filename, true) # set to delete tempfile on create
        self
      end

      private

      # Little helper method - no need to load the pdf classes unless needed,
      # but if called every time round it will slow things down (in Rails it will).
      def self.activate_pdf
        return if(@pdf_active)
        require 'pdf/writer'
        @pdf_active = true
      end

      def activate_pdf
        self.class.activate_pdf
      end

    end
    
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
talia_core-0.5.4 lib/talia_core/data_types/pdf_data.rb
talia_core-0.5.3 lib/talia_core/data_types/pdf_data.rb
talia_core-0.5.2 lib/talia_core/data_types/pdf_data.rb
talia_core-0.5.1 lib/talia_core/data_types/pdf_data.rb
talia_core-0.5.0 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.22 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.20 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.19 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.18 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.17 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.16 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.15 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.14 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.13 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.12 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.11 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.10 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.9 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.8 lib/talia_core/data_types/pdf_data.rb
talia_core-0.4.7 lib/talia_core/data_types/pdf_data.rb