Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### reports_helper.rb
- module ReportsHelper
- module Large
- font_size = 12
- cols = 3
- labels_per_page = 30
- labels_per_col = 10
- marg_x = 72 * 0.19
- marg_y = 72 * 0.5
- cell_x = 72 * 2.63
- cell_y = 72 * 1
- col_pad_x = 72 * 0.19
- col1_x = marg_x
- col2_x = col1_x + cell_x + col_pad_x
- col3_x = col2_x + cell_x + col_pad_x
- cell_pad_x = 72 * 0.13
- cell_pad_y = 72 * 0.25
- cell_line_y = font_size + 2
- def cell_x(col)
- [col1_x, col2_x, col3_x][col] + cell_pad_x
- end
- def cell_y(row, line)
- marg_y + ((labels_per_col - row) * cell_y) - cell_pad_y - (line * cell_line_y)
- end
- def add_label(row, col, user, pdf)
- pdf.text "Name: #{user.full_name}"
- user.addresses.each do |a|
- pdf.text a.addr1
- pdf.text a.addr2 unless a.addr2.blank?
- if (a.country == "United States" || a.country.blank?)
- pdf.text "#{a.city}, #{a.state}, #{a.postal_code}"
- else
- pdf.text "#{a.city} #{a.state}"
- pdf.text a.postal_code
- pdf.text a.country
- end
- pdf.text ""
- end
- end
- end
- end
- ### mailing_labels.pdf.prawn
- pdf.font "Helvetica"
- pdf.font.size = Large::font_size
- pages = @users.length / Large::labels_per_page
- pages += 1 if (@users.length % Large::labels_per_page) > 0
- 0.upto(pages - 1) do |page|
- start = page * Large::labels_per_page
- users_page = @users[start..start + Large::labels_per_page]
- 0.upto(Large::LABELS_PER_COL - 1) do |row|
- Large::add_label(row, 0, user_page[row * Large::cols ], pdf)
- Large::add_label(row, 1, user_page[row * Large::cols + 1], pdf)
- Large::add_label(row, 2, user_page[row * Large::cols + 2], pdf)
- end
- pdf.new_page unless page + 1 == pages
- end
Add Comment
Please, Sign In to add comment