Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a multipage PDF in Rails representing one table of data (including column headers on each new page)?

How to create a multipage PDF in Rails representing one table of data (including column headers on each new page)? I've looked at many examples with wicked-pdf, pdfkit, and prawn but haven't seen anything that specifically addresses the overflow into subsequent pages and the need to repeat the headers with each new page. Thanks for the help.

like image 844
ob1 Avatar asked Jan 27 '26 07:01

ob1


1 Answers

I use Prawn to generate my pdfs, and can get the effect you desire like this:

def render_photo_table(pdf)
  ps = self.photos.map do |photo|
    [photo.filename, photo.image_height, photo.image_width]
  end
  ps.insert(0, ['Filename', 'Height', 'Width'])
  pdf.table(ps) do |table|
    table.header = true
  end
end

This yields a header (set in array position 0) at the top of each page.

like image 169
railsdog Avatar answered Jan 29 '26 03:01

railsdog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!