首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >对虾-在表格单元格中添加图像和文本。

对虾-在表格单元格中添加图像和文本。
EN

Stack Overflow用户
提问于 2014-01-14 11:08:50
回答 1查看 4.1K关注 0票数 5

是否可以使用gem对虾将图像文本嵌入到表格单元格中?

我用的是gem "prawn", "~> 0.13.2"

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

Rails版本: 3.2.13和Ruby2.0.0

EN

回答 1

Stack Overflow用户

发布于 2014-01-14 19:23:25

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

代码语言:javascript
运行
复制
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-文档的表格单元格的代码:

代码语言:javascript
运行
复制
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, ""]])

有关自定义表单元格映像的详细信息:查看对虾文档

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21112037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档