I am having trouble with how to create a two-column bulleted list using prawn PDF and prawn/table. I wanted to know if there is a way to do it that's not too custom/uses existing classes to take care of overflow to a new page, etc so I don't miss things or reinvent the wheel.
I want the list to look something like this:
*Name 1 * Name 3
*Name 2 * Name 4
... ...
Currently what I have is:
bullet_list = [
[ '*' , 'Name 1' ],
[ '*' , 'Name 2' ],
[ '*' , 'Name 3' ],
[ '*' , 'Name 4' ]
]
pdf.table(bullet_list, {:cell_style => { :borders => [], :align => :justify, :padding => [0,10,0,0]}})
This obviously makes a bullet list straight down, but it seemed to be a decent start, but will I need to split the list, create the list down with the first half, go back up the PDF some amount, go right, and repeat the process?
Another thing I was thinking of was using inline HTML styling as seen here https://prawnpdf.org/manual.pdf (Pg. 53) but I think it only accepts very basic styling like bold/italics.
Any tips would be greatly appreciated!
Alright so I ended up using the table method, I'm not sure why I didn't think of this earlier but we can just split the list of names in half and append them in such a way that the second half of names is appended to the same row as the first half of names. Here is essentially what I did:
require 'active_support/core_ext/array/grouping'
require 'prawn'
require 'prawn/table'
names = ['John', 'Jim', 'Joe', 'James']
pdf = Prawn::Document.new
split_names = names.in_groups(2, false)
split_names.first.each do |name|
bullet_list << ["\u2022", name]
end
split_names.second.each_with_index do |name, index|
bullet_list[index].push("\u2022", name)
end
pdf.table(bullet_list, { cell_style: { borders: [], align: :justify, padding: [0, 10, 0, 0] } })
This is a solution that works but let me know if you have any tips or changes that should be made.