#!/usr/bin/ruby -w # # Testing Prawn PDF generation require 'rubygems' require 'prawn' require 'prawn/layout' require 'prawn/format' class TermSheet < Prawn::Document def initialize(options={}) @recipient = options[:recipient] @recipient_addy = options[:recipient_addy] @ticket = options[:ticket] @sales_rep = options[:sales_rep] @doc_no = options[:doc_no] @project = options[:project] @date = options[:date] super end def draw_term_sheet line_width(0.2) font_size(8) nframe_address info_table recipient_address hr draw_footer end def save_as(file) draw_term_sheet render_file(file) end def info_table tags :blue => { :color => 'blue' }, :green => { :color => 'green' } bounding_box [235, 700], :width => 300 do font "Times-Roman" fill_color('999999') text "TERM SHEET", :size => 24, :align => :right fill_color('000000') font "Helvetica" text "Keep IT Safe, Keep IT Simple", :size => 12, :align => :right end bounding_box [260, 650] do table [[@ticket, @sales_rep, @doc_no, @project, @date]], :headers => ['TICKET', 'SALES REP', 'DOC. NO.', 'PROJECT NO.', 'DATE'], :header_color => '000000', :header_text_color => 'ffffff', :align_headers => :center, :vertical_padding => 2, :horizontal_padding => 2, :font_size => 8, :width => 272, :border_width => 0.2, :align => { 0 => :center, 1 => :center, 2 => :center, 3 => :center, 4 => :center, 5 => :center, 6 => :left } end end def nframe_address address = <<-EOF 701 Congressional Blvd. Ste 100 Carmel, IN 46032 Phone: (317) 805-3759 Fax: (317) 324-9013 Web: www.nframe.com EOF bounding_box [0, 700], :width => 130 do nframe = "nframe.jpg" image nframe, :scale => 0.25 text address, :size => 6 end end def recipient_address pad_bottom(5) do bounding_box [100, 700], :width => 150, :height => 95 do line bounds.top_left, bounds.top_right line bounds.top_left, bounds.bottom_left line bounds.top_right, bounds.bottom_right line bounds.bottom_right, bounds.bottom_left padded_box(5) do text "TO: #{@recipient.upcase}" stroke_horizontal_rule text @recipient_addy end end end end def hr stroke_horizontal_rule end def draw_footer footer [margin_box.left, margin_box.bottom + 25] do pad_bottom(3) do text "Freq. = Frequency | MRC = Monthly Recurring Charge | NRC = Non-Recurring Charge | Term = Term in Months" end hr pad(5) do text "#{@date} \t To: #{@recipient} \t\t #{@doc_no} \t \"Keep IT Safe, Keep IT Simple\" " text "CONFIDENTIAL", :size => 16, :at => [bounds.right - (font_size * 16), bounds.top - 32] end end end end customer_addy = < customer_addy, :recipient => 'Indifferent Enigmas', :ticket => '0', :sales_rep => 'Frodo Baggins', :doc_no => 'NFIQ3836', :project => 'NFIPROJECT2553', :date => '5/15/2006') i.save_as('term_sheet.pdf')