prawnto displaying tables that don't break when new page

后端 未结 4 744
面向向阳花
面向向阳花 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:30

    4 years later... :)

    As @m-x wrote it, rollback was disabled for security reason, like "group", and is still not implemented. So, here how I deal with break pages for tables :

    Big and simple table (one row per data)

    Just use header option

    pdf.table @data,
      header: true, # You can use 'header: 2' if your header take two rows
      font_size: 12, 
      border_style: :grid,
      horizontal_padding: 10,
      vertical_padding: 3,
      border_width: 2,
      position: :left,
      row_colors: ["FFFFFF","DDDDDD"]
    

    Small table or complexe table

    • make table
    • check if you need break page
    • draw table

    With your example :

    t = pdf.make_table @data,
      font_size: 12, 
      border_style: :grid,
      horizontal_padding: 10,
      vertical_padding: 3,
      border_width: 2,
      position: :left,
      row_colors: ["FFFFFF","DDDDDD"]
    
    if cursor - t.height < 0
      start_new_page
    end
    
    t.draw
    

    Hope that helps

提交回复
热议问题