#!/usr/bin/ruby # # 2013-08-19 - NewMexicoKid # # gem install prawn # gem install fastercsv # require "rubygems" require "prawn" require 'open-uri' require "prawn/measurement_extensions" require 'fastercsv' # 2.5 in wide; 1 in tall # 0,0 is at the lower left of the page. # For iterating over the page of cards (3 columns x 10 rows) columns = Array(0..2) rows = Array(0..9) # Basic page template template_filename = 'idea_ring_cards_130812_flipped.pdf' # colors red = 'CE1E1E' green = '0F6D08' blue = '0740B2' output_file = 'idea_ring_wavy2_reverse_' + Time.now.strftime('%Y-%d-%m') + '.pdf' Prawn::Document.generate(output_file,options = {:template => open(template_filename)}) do # location of starting idea ring block, lower left x0 = 0.00.in y0 = 1.00.in # location of starting writing prompt block, lower left x1 = 0.65.in y1 = 0.85.in # starting locations for the word pairs (blocks will be rotated 90 degrees) y2 = 0.95.in x2 = 0.2.in x3 = 0.4.in x4 = 0.6.in # main idea cards dimensions boxwidth = 2.5.in boxheight = 1.0.in # initialization row_j = 0 alldata = Array.new count = 0 # Read in data from ;-separated values, no headers; copy each row to the array alldata FasterCSV.foreach("data3.csv", :quote_char => '"', :col_sep =>';', :row_sep =>:auto) do |row| #DEBUG puts "Count is " , count alldata[count] = row.clone count += 1 end # Iterate over all rows and columns count = 0 rows.each do |row_j| columns.each do |column_i| # writing prompt (horizontal orientation) x = x1 + boxwidth*column_i y = y1 + boxheight*row_j #DEBUG print "x = ",x," and y = ",y," for count = ",count,"\n" text_box alldata[count][0], :at => [x,y], :width=>1.25.in, :height => 0.7.in, :overflow => :shrink_to_fit # word pair #1 x = x2 + boxwidth*column_i y = y2 + boxheight*row_j formatted_text_box [ { :text => alldata[count][1], :color => green, :styles => [:italic], :size => 9 }], :at => [x,y], :width=>0.90.in, :height => 0.2.in, :overflow => :shrink_to_fit, :rotate => -90 # word pair #2 x = x3 + boxwidth*column_i formatted_text_box [ { :text => alldata[count][2], :color => blue, :styles => [:italic], :size => 9 }], :at => [x,y], :width=>0.90.in, :height => 0.2.in, :overflow => :shrink_to_fit, :rotate => -90 # word pair #3 x = x4 + boxwidth*column_i formatted_text_box [ { :text => alldata[count][3], :color => red, :styles => [:italic], :size => 9 }], :at => [x,y], :width=>0.90.in, :height => 0.2.in, :overflow => :shrink_to_fit, :rotate => -90 # overlaid image x = x0 + boxwidth*column_i y = y0 + boxheight*row_j bounding_box([x, y], :width => boxwidth, :height => boxheight) do transparent(0.5) do image "wavy_idea_ring2_reverse.png", :fit => [boxwidth, boxheight] # stroke_bounds end end count += 1 end end end