Sha256: c4d0c6167c6a23e78db4ffa06e1d9586e121500ab3fd70af2338cbfddd014db6
Contents?: true
Size: 1.49 KB
Versions: 3
Compression:
Stored size: 1.49 KB
Contents
module Medivo class PdfGroup attr_reader :pdf def initialize @pdfs = [] end ## # create a pdf group returns you a PdfGroup class # to get the pdf call #pdf, or read the pdf byes, call #read def self.create(&block) raise "need to pass a block do create" unless block_given? pdf_group = PdfGroup.new pdf_group.instance_eval &block pdf_group.combine_pdfs pdf_group end ####### the types of pdfs you could make ########## def variable_fields(file_path, variables) @pdfs << PdfGenerator.variable_fields(file_path, variables) end def lab_requisition(requisition_id) pdf_bytes = Medivo::Order.pdf_requisition(requisition_id) @pdfs << PdfGenerator.tmp_pdf {|pdf| pdf.write pdf_bytes } end def lab_result(requisition_id) pdf_bytes = Medivo::Order.pdf_result(requisition_id) @pdfs << PdfGenerator.tmp_pdf {|pdf| pdf.write pdf_bytes } end def static_pdf(path) @pdfs << File.new(path) end ## # Combines the PDFs def combine_pdfs @pdf = PdfGenerator.tmp_pdf do |pdf| args = [@pdfs.collect(&:path), 'cat', 'output', pdf.path].flatten system 'pdftk', *args @pdfs.collect do |file| file.close file.unlink if file.respond_to? :unlink end end end # trying to keep the pdf ( tempfile ) closed until you need it then closing again def read @pdf.open @pdf.read @pdf.close end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
medivo-0.1.14 | lib/pdf/medivo/pdf_group.rb |
medivo-0.1.13 | lib/pdf/medivo/pdf_group.rb |
medivo-0.1.12 | lib/pdf/medivo/pdf_group.rb |