class PdfPrinter < ActionPrinter #IKKE FÆRDIG def do_render(print_job,*args) path = print_job.view_template_path # TODO vi får en fejl her når vi begynder at mixe modellerne f.eks. Employee.find_by_sql('select * from products') locals = { resource_class: print_job.printing_class.constantize, collection: print_job.printing_class.constantize.find_by_sql( print_job.print_sql) } # # TODO args must be mergeable ;) # if args.flatten.compact.any? # locals.merge! args # end # html = ActionView::Base.new(Rails.configuration.paths['app/views']).render( # file: 'accounts/record.html.haml', # # partial: 'test', # formats: [:html], # handlers: [:erb,:haml], # locals: { variable: 'value' } # ) # of = html_file render( file: path, formats: [:html], handlers: [:haml,:erb], locals: locals) logit :info, "created a html file: #{of.path}" # # calls java -jar with the oxen_printer gem lib/java_pdf/barcodeprinter.jar - as in java -jar /Users/walther/Projects/Gems/oxen_printer/lib/java_pdf/barcodeprinter.jar $1 $2 var = %x[ bin/printer_cmd.sh #{of.path} #{pdf_file_path} ] logit :info, "converted the html file to a PDF file: #{pdf_file_path}" true rescue => e logit :error, "Rendering to PDF failed! The error was #{e.message}" false end def do_print copies result = nil prn = printer unless prn.command.blank? pdf_path = pdf_file_path.split("/")[-1] pap = paper || prn.paper cmd = prn.command.gsub( /\$1/, prn.cups_printer ).gsub( /\$2/, pap ).gsub( /\$3/, pdf_file_path ).gsub( /\$4/, pdf_path ) if copies > 1 cmdargs = cmd.split(" ") f = cmdargs.pop cmdargs.push "-n", copies, f cmd = cmdargs.join(" ") end # Here we start actually printing # $1 is the CUPS printer # $2 is the PDF file_path_and_name # $3 is the PDF filename # the command being something along the lines of: lp -d $1 -o media=a4 $2 return `#{cmd}` end rescue false end def file_path pdf_file_path end def get_file_type "application/pdf" end end