【问题标题】:Prawn - Adding an image along with text in a table cellPrawn - 在表格单元格中添加图像和文本
【发布时间】:2014-01-14 11:08:50
【问题描述】:

是否可以使用 gem prawn 在表格单元格中嵌入 图像 和 文本?

我正在使用gem "prawn", "~> 0.13.2"

我可以只嵌入图像或文本。但是,两者都不是。请帮忙。

Rails 版本:3.2.13 和 Ruby 2.0.0

【问题讨论】:

  • Prawn 似乎不支持这种开箱即用的功能。

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


【解决方案1】:

以下是手册中有关如何将图像和文本插入 PDF 文档的代码:

text "Scale by setting only the width"
image "#{Prawn::DATADIR}/images/pigs.jpg", :width => 150
move_down 20

text "Scale by setting only the height"
image "#{Prawn::DATADIR}/images/pigs.jpg", :height => 100
move_down 20

text "Stretch to fit the width and height provided"
image "#{Prawn::DATADIR}/images/pigs.jpg", :width => 500, :height => 100

以下是手册中有关如何将图像和文本插入 PDF 文档的表格单元格的代码:

cell_1 = make_cell(:content => "this row content comes directly ")
cell_2 = make_cell(:content => "from cell objects")
two_dimensional_array = [ ["..."], ["subtable from an array"], ["..."] ]
my_table = make_table([ ["..."], ["subtable from another table"], ["..."] ])
image_path = "#{Prawn::DATADIR}/images/stef.jpg"

table([ ["just a regular row", "", "", "blah blah blah"],
    [cell_1, cell_2, "", ""],
    ["", "", two_dimensional_array, ""],
    ["just another regular row", "", "", ""],
    [{:image => image_path}, "", my_table, ""]])

有关自定义表格单元格图像的更多信息:Check out the Prawn documentation

【讨论】:

  • 我在询问如何将图像和文本插入单个表格单元格。这就是你上面解释的吗?
  • @RajeshCO 不是代码解决方案的第二部分和第一部分吗?
  • 您可以在单个单元格内使用没有边框的两行一列子表来获取您要查找的内容。
  • 我们如何做类似table([["`string1`"], [["`string2`", "`string2.5`"]], ["`string3`]]]) 的事情?
  • @VishwasNahar ypu 对 `string1` 意味着什么??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-06
  • 1970-01-01
  • 1970-01-01
  • 2019-04-24
相关资源
最近更新 更多