# ## this is how looked my old pdf-action in the controler... ugh! # --comments are in italian, for italian I am, of course that's not the point!-- # in the controller with PDF::Writer # PDF-WRITING def export_pdf @estimate = Estimate.find params[:id], :include=>[:estimate_items, :project, :company] render(:update) {|p| p.alert "non si può stampare un preventivo senza articoli, totale o cliente"} if @estimate.estimate_items.empty? pdf = PDF::Writer.new :paper=>"A4" #A4 595.28 pts � 841.89 pts #Per impostare i margini del documento in (mm) #A4 595.28 pts � 841.89 pts pdf.margins_pt 51.89, 47.64, 40, 47.64 #area disponibile: 500 � 750 pdf.select_font("Helvetica", :encoding => nil) pdf.fill_color Color::RGB::Black # pdf.add_image(RAILS_ROOT+"/public/images/logo_mdm.png", 47.64, 741.89, 60, 25 )#:resize => 0.40 pdf.image RAILS_ROOT+"/public/images/logo_mdm.png", :resize => 0.40 pdf.move_pointer(-52, true) pdf.text "mdm s.r.l.", :justification=>:right, :font_size=>14 text = <<-EOS sede operativa: via pollini 3 20125 MILANO tel +39/02/45470638 fax +39/02/45470641 www.mdmsrl.it EOS pdf.text text, :justification=>:right, :font_size=>8 pdf.move_pointer(20, true) pdf.text "Preventivo n.#{@estimate.id.to_s} per #{@estimate.company.full_name}", :justification=>:left, :font_size=>20 pdf.move_pointer(10, true) pdf.text "OGGETTO:", :font_size=>8 pdf.text @estimate.subject, :font_size=>11 if @estimate.notes pdf.move_pointer(10, true) pdf.text "NOTE:", :font_size=>8 pdf.text @estimate.notes, :font_size=>11 end pdf.move_pointer(10, true) pdf.text "ELENCO ARTICOLI", :font_size=>8, :justification=>:center pdf.move_pointer(10, true) PDF::SimpleTable.new do |tab| tab.width = 500 tab.orientation = :center tab.bold_headings = true tab.column_order= ["description", "unit_price", "quantity", "partial"] tab.columns["description"] = PDF::SimpleTable::Column.new(:description) do |col| col.heading = "DESCRIZIONE" end tab.columns["unit_price"] = PDF::SimpleTable::Column.new(:unit_price) do |col| col.justification = :right col.heading = PDF::SimpleTable::Column::Heading.new( "PREZZO UNITARIO Euro" ){|h| h.justification = :center } end tab.columns["quantity"] = PDF::SimpleTable::Column.new(:quantity) do |col| col.justification = :right col.heading = PDF::SimpleTable::Column::Heading.new( "QUANTITA'" ){|h| h.justification = :center } end tab.columns["partial"] = PDF::SimpleTable::Column.new(:partial) do |col| col.justification = :right col.heading = PDF::SimpleTable::Column::Heading.new( "TOTALE Euro" ){|h| h.justification = :center } end tab.heading_font_size = 8 tab.show_lines = :all tab.show_headings = true tab.line_color = Color::RGB::Grey50 tab.outer_line_style = PDF::Writer::StrokeStyle.new(0.5) tab.inner_line_style = PDF::Writer::StrokeStyle.new(0.5) tab.shade_color = Color::RGB::Grey90 @estimate.estimate_items.each_with_index do |item, index| # tab.data<< item.attributes.update(:partial => item.quantity*item.unit_price) row = { "partial"=> item.quantity*item.unit_price, "quantity"=> item.quantity.to_s + " " + item.item_type, "unit_price"=> item.unit_price, "description"=> item.description } tab.data<< row end #riga totale tab.data<< {} if @estimate.estimate_items.length.even? # tab.data<< {} if @estimate.estimate_items.length.odd? tab.data<< {"partial"=> "Totale:"} tab.data<< {} tab.data<< { "partial"=> @estimate.total } tab.render_on(pdf) end pdf.save_as(RAILS_ROOT+"/public/pdf_documents/prova.pdf") send_data pdf.render, :filename => "Preventivo #{@estimate.project_name} del #{@estimate.updated_at.to_date.to_s}.pdf", :type => "application/pdf" end