gpt4 book ai didi

ruby - 具有colspan和width的表格单元格的Prawn CannotFit错误

转载 作者:太空宇宙 更新时间:2023-11-03 17:54:29 24 4
gpt4 key购买 nike

尝试创建类似 http://rghost.ru/46587227.view 的表时对于 Prawn,它会导致 CannotFit 错误:

first = {:content=>"Foooo fo foooooo",:width=>50,:align=>:center}
second = {:content=>"Foooo",:colspan=>2,:width=>70,:align=>:center}
third = {:content=>"fooooooooooo, fooooooooooooo, fooo, foooooo fooooo",:width=>55,:align=>:center}
fourth = {:content=>"Bar",:width=>20,:align=>:center}

table_content = [[
first,
[[second],[third,fourth]]
]]
pdf.move_down(20)
pdf.table(table_content)

最佳答案

Prawn 在使用 colspan 计算单元格大小时遇到​​问题。

我能够按照以下规则解决此问题:

  • 不要将 width 分配给具有 colspan 的单元格>
  • 给表格正确的总宽度

应用于您的示例

 first = { content: "Foooo fo foooooo", rowspan: 2, width: 50 }
second = { content: "Foooo", colspan: 2 } # <- avoid width here!
third = { content: "fooooooooooo, fooooooooooooo, fooo, foooooo fooooo", width: 55 }
fourth = { content: "Bar", width: 20 }

Prawn::Document.generate("test.pdf") do |pdf|
table_content = [ [first, second ],
[ third, fourth],
[1, 2, 3 ] ]
pdf.move_down(20)
pdf.table(table_content, width: 50+55+20, cell_style: {align: :center})
end

输出

PDF

关于ruby - 具有colspan和width的表格单元格的Prawn CannotFit错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16989973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com