【问题标题】:How to align the header and the column properly in prawn pdf?如何在虾pdf中正确对齐标题​​和列?
【发布时间】:2012-08-06 20:38:54
【问题描述】:

我们正在用 rails 3.1.4 中的大虾生成发票的 pdf。

  header =[[  "Date", "#", "sample name", "model","lease item", "hours", "$/hour", "Total"]]
  items = @invoice.invoice_items.map do |item|
    [
                item.lease_usage_record.lease_usage_items.map do |li|
                [
                  li.lease_date.strftime("%Y-%m-%d"),
                  item.lease_usage_record_id,
                  li.sample_name,
                  li.sample_model_num,
                  li.lease_item.short_name,          
                  li.total_hour,
                  li.charge_rate,
                  li.subtotal
                ]
                end
    ] 
  end
items = header + items
pdf.table items, :header => true, :width => 480 
t = pdf.make_table([ ["                                                       ", "Total:     ","    #{@invoice.total}"] ])
t.draw

它可以解决问题。问题是所有数据单元都被压缩到第一列,即“日期”。试图在标题中再添加一个 [] 并生成“数据是二维数组......”的错误。如何在标题下正确对齐每一列?非常感谢。

【问题讨论】:

    标签: pdf pdf-generation prawn prawnto


    【解决方案1】:

    通过将数据(项目)的维度减少到二维来解决问题。大虾只能取二维数据。以下行可以解决问题:

    items = items.flatten(2)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 2015-05-19
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 2012-11-26
      相关资源
      最近更新 更多