Sha256: 4e1555601019d2f9e1b58a76a0174dd924f31cc6b42a8f720da5a67ac51d7049

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

# coding: utf-8

begin
  gem 'prawn', '0.12.0'
  require 'prawn'
rescue LoadError
  puts 'ThinReports requires Prawn = 0.12.0. ' +
       'Please `gem install prawn -v 0.12.0` and try again.'
end

module ThinReports
  module Generator
    
    class PDF < Base
      # @param report (see ThinReports::Generator::Base#initialize)
      # @param [Hash] options
      # @option options [Hash] :security (nil)
      #   See Prawn::Document#encrypt_document
      def initialize(report, options)
        super
        @pdf = Document.new(options, :Title => default_layout.format.report_title)
        
        @drawers = {}
      end
      
      # @see ThinReports::Generator::Base#generate
      def generate
        draw_report
        @pdf.render
      end
      
      # @see ThinReports::Generator::Base#generate_file
      def generate_file(filename)
        draw_report
        @pdf.render_file(filename)
      end
      
    private
      
      def draw_report
        report.pages.each do |page|
          draw_page(page)
        end
      end
      
      def draw_page(page)
        return @pdf.add_blank_page if page.blank?
        
        format = page.layout.format
        @pdf.start_new_page(format)
        
        drawer(format).draw(page.manager)
      end
      
      def drawer(format)
        @drawers[format.identifier] ||= Drawer::Page.new(@pdf, format)
      end      
    end
    
  end
end

require 'thinreports/generator/pdf/configuration'
require 'thinreports/generator/pdf/prawn_ext'
require 'thinreports/generator/pdf/document'
require 'thinreports/generator/pdf/drawer'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thinreports-0.7.5 lib/thinreports/generator/pdf.rb
thinreports-0.7.0 lib/thinreports/generator/pdf.rb