【发布时间】:2015-08-06 13:16:01
【问题描述】:
尝试使用 Rails 的 Prawn gem 生成文档时遇到问题
我要做的是为我的 pdf 设置可变高度,因此根据数据库中的一些查询,PDF 高度会改变。我这样做是因为我需要一个单页 PDF 文档。
目前,我的代码如下所示:
pdf = Prawn::Document.new(page_size: [297.64, 419.53], margin: 0)
....
data = [ ["Header1", "Header2", "Header3", "Header4", "Header5", "Header6"] ]
// here is the variable data
cart.cart_products.each do |cp|
arr = [
cp.product_code,
cp.product_description,
cp.amount,
cp.product_metric,
cp.product_unit_value,
cp.total_value
]
data.push(arr)
end
// populating the table with data
pdf.table(data, :cell_style => {:border_width => 0}, :column_widths => [45, 80, 30, 42.36, 50, 50]) do |table|
table.row(0).border_width = 0.1.mm
table.row(0).font_style = :bold
table.row(0).borders = [:bottom]
end
....
pdf.render_file("path/to/dir/document.pdf")
谁能帮我解决这个问题?谢谢。
【问题讨论】:
标签: ruby-on-rails pdf prawn