Guest User

Untitled

a guest
Feb 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. # cell widths
  2. cell_widths = [160,60]
  3.  
  4. # example data for rows_to_pdf
  5. rows_to_pdf = [
  6. ['Row Name','200',300','400'],
  7. ['Row Name','200',300','400'],
  8. ['Row Name','200',300','400'],
  9. ['Row Name','200',300','400'],
  10. ['Row Name','200',300','400']
  11. ]
  12.  
  13. # build the row of cells
  14. pdf.font 'Helvetica'
  15. pdf.text_options.update(:size => 8)
  16. rows_to_pdf.each do |cells|
  17. new_cells = []
  18. cells.each_with_index do |old_cell,cell_index|
  19. new_cells << Prawn::Graphics::Cell.new(
  20. :border_width => 0.5, :horizontal_padding => 1, :vertical_padding => 0,
  21. :width => (cell_index>0 ? cell_widths[1] : cell_widths[0]),
  22. :align => (cell_index>0 ? :right : :left),
  23. :text => old_cell, :borders => [:bottom], :document => pdf)
  24. end
  25. cellblock = Prawn::Graphics::CellBlock.new(pdf)
  26. new_cells.each do |new_cell|
  27. cellblock << new_cell
  28. end
  29. pdf.move_down(1)
  30. cellblock.draw
  31. end
Add Comment
Please, Sign In to add comment