【问题标题】:How to add an image to a table with Prawn?如何使用 Prawn 将图像添加到表格中?
【发布时间】:2011-08-29 08:31:02
【问题描述】:

所以我有以下代码:

items = [ ["Photo","Name", "Qty", "Unit Price", "Amount"] ]
items += @quotation.quotation_items.map do |oitem|
[
   pdf.image(oitem.item.photo),
   oitem.item.title,
   oitem.quantity.to_s,
   number_to_currency(oitem.item.price,:unit => 'HK$ '),
   number_to_currency(oitem.full_price,:unit => 'HK$ ')
]

这会产生错误:

Content type not recognized: #<Prawn::Images::JPG:0x00000101703b98 @bits=8, @height=300, @width=300, @channels=3, @scaled_width=300, @scaled_height=300>

提取的源代码(第 54 行附近):

51: 
52: end
53: 
54: pdf.table items, :header => true,
55:                  :column_widths => [300,200,100,150,150],
56:                  :row_colors => ["FFFFFF","DDDDDD"]
57: 

【问题讨论】:

  • 据我所知,图像对象在表格单元格 prawn suitable cell types 中是不可接受的。您可能必须为每个边界框循环而不是表做一个。

标签: ruby-on-rails ruby-on-rails-3 prawn


【解决方案1】:

刚刚发现一张带有图像的模拟表,对我帮助很大。感谢 jfeust 与我们分享。 - https://gist.github.com/973267

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-10
    • 1970-01-01
    相关资源
    最近更新 更多