Sha256: edc8e6a407eac8fff83f152e492f09e1c46860a6769978b5aa4b592b1d81480c

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

module Medivo
  class PdfGroup
    def initialize
      @pdfs = []
    end

    def self.create(&block)
      raise "need to pass a block do create" unless block_given?
      pdf_group = PdfGroup.new
      yield pdf_group
      # combine the pdfs
      pdf_group.pdf
    end

    def variable_fields(file_path, variables)
      @pdfs << PdfGenerator.variable_fields(file_path, variables)
    end

    def lab_requisition(requisition_id)
      pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit')
      pdf.write Medivo::Order.pdf_requisition(requisition_id)
      pdf.close
      @pdfs << pdf
    end

    def lab_result(requisition_id)
      pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit')
      pdf.write Medivo::Order.pdf_result(requisition_id)
      pdf.close
      @pdfs << pdf
    end

    ##
    # Combines the PDFs
    def pdf
      pdf = Tempfile.new('pdf', :encoding => 'ascii-8bit')
      args = [@pdfs.collect(&:path), 'cat', 'output', pdf.path].flatten
      system 'pdftk', *args
      pdf
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
medivo-0.1.5 lib/pdf/medivo/pdf_group.rb
medivo-0.1.4 lib/pdf/medivo/pdf_group.rb