尝试使用Prawn创建http://rghost.ru/46587227.view这样的表时,会导致出现一个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)
答案 0 :(得分:4)
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