prawnto displaying tables that don't break when new page

后端 未结 4 742
面向向阳花
面向向阳花 2021-02-10 09:46

I have a variable number of tables with variable number of rows and I want to have them displaying one after the other but if a table doesn\'t fit on the current page put it on

4条回答
  •  逝去的感伤
    2021-02-10 10:10

    I'm a Prawn beginner, so this might not be the best solution, but it should work.

    You can get the table height if you consider the font size and vertical padding and the number of records you have in @data and you can get the current cursor position by calling Prawn::Document.cursor method.

    Having these two numbers you should be able to check whether the table fits on this page or not. If not, just start a new one (by calling Prawn::Document.start_new_page method).

    Otherwise the table will break automatically and will continue on the next page.

提交回复
热议问题