Skip to content

Commit

Permalink
Added PDF card printing
Browse files Browse the repository at this point in the history
  • Loading branch information
makenai committed Jan 4, 2012
1 parent 86ce504 commit 2484f43
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion app/controllers/members_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'csv'
require 'prawn'

class MembersController < ApplicationController

Expand All @@ -13,14 +14,27 @@ def index
end
respond_to do |format|
format.html
format.pdf do
pdf = nil
@members.each do |member|
if pdf
pdf.start_new_page :template => Rails.root.join('pdfs/card.pdf')
else
pdf = Prawn::Document.new :template => Rails.root.join('pdfs/card.pdf')
pdf.font Rails.root.join('pdfs/MONACO.TTF')
end
pdf.draw_text "usr://#{ member.name.to_s.downcase.gsub(/\s+/,'.')}", :size => 10, :at => [-15,-8]
end
send_data( pdf.render, :filename => "members-#{Time.now.strftime('%Y-%m-%d')}.pdf", :type => 'application.pdf' ) if pdf
end
format.csv do
csv = CSV.generate do |csv|
csv << [ 'name', 'email', 'number' ]
@members.each do |member|
csv << [ member.name.to_s.downcase.gsub(/\s+/,'.'), member.user.email, member.card_number ]
end
end
send_data( csv, :filename => 'members.csv', :type => 'text/csv' )
send_data( csv, :filename => "members-#{Time.now.strftime('%Y-%m-%d')}.csv", :type => 'text/csv' )
end
end
end
Expand Down
1 change: 1 addition & 0 deletions config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

# Initialize the rails application
Usrshare::Application.initialize!
Mime::Type.register 'application/pdf', :pdf
Binary file added pdfs/MONACO.TTF
Binary file not shown.
Binary file added pdfs/card.pdf
Binary file not shown.

0 comments on commit 2484f43

Please sign in to comment.