Search code examples
rubyprawn

Ruby + Prawn PDF: How to add space prefix in string inside of a table?


I have a two dimensional array:

    line_items = []
    line_item.product.book_versions.each do |book_version|
        data = []
        data << ""
        data << "     #{book_version.book.title} - #{book_version.isbn}" #<-- notice the extra spaces in the beginning of the string
        data << "#{line_item.quantity}"
        line_items << data
    end

And I load this data into my table with pdf.table line_items ... do ... end

However, the extra spaces in my 2nd column don't show up. How would I escape these spaces so that they aren't stripped?


Solution

  • Your best bet will probably be to use a custom padding for that column. Something like this:

    pdf.table line_items do
      column(1).padding = [5, 5, 5, 30] # Default padding is 5; just increase the left padding
      ...
    end