prawnto 显示新页面时不会破坏的表格 [英] prawnto displaying tables that don't break when new page

查看:50
本文介绍了prawnto 显示新页面时不会破坏的表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有可变数量的表格和可变数量的行,我想让它们一个接一个地显示,但如果一个表格不适合当前页面,则将其放在下一个页面上,然后继续.我已将表格放入事务中,因此如果高度适合当前页面,我可以回滚然后打印它,但如何获得表格高度?

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 the next then continue on. I have put the table in a transaction so I can roll back then print it if the height will fit on curent page but how do I get the table height?

我现在有这个代码

pdf.transaction do 

pdf.table @data,
    :font_size  => 12, 
    :border_style => :grid,
    :horizontal_padding => 10,
    :vertical_padding   => 3,
    :border_width       => 2,
    :position           => :left,
    :row_colors => ["FFFFFF","DDDDDD"]

pdf.move_down 20

#pdf.rollback 
end

对此的任何帮助都会很棒.或者任何其他方式来做到这一点?

Any help on this would be great. Or any other way to do this ?

最好的问候瑞克

推荐答案

4 年后... :)

正如@m-x 所写,出于安全原因,回滚被禁用,例如组",并且仍未实现.所以,在这里我如何处理表格的中断页:

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 :

只需使用标题选项

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"]

小桌子或复合桌子

  • 制作桌子
  • 检查您是否需要分页
  • 画表
  • 以你的例子:

    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
    

    希望有帮助

    这篇关于prawnto 显示新页面时不会破坏的表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆