用 Prawn 在表格/单元格内绘制格式化文本

发布于 2024-10-01 18:42:46 字数 408 浏览 0 评论 0原文

我正在使用 prawn-0.11.1.pre 运行 Rails 3.0.1

我只是做了一些基本测试,看看是否可以让 Prawn 创建一个包含一些格式化文本的简单表格:

data = ["Cell 1", formatted_text([{:text => "Cell 2"}])], 
       ["Cell 3","Cell 4"]
table(data)
render

PDF 呈现如下

Cell 2
[Cell 1][      ]
[Cell 3][Cell 4]

(一个不错的表格,但带有表格外的文本“单元格 2”)

我的目标是在单元格 #2 内获取格式化文本“单元格 2”...

我应该怎么做?

I am running Rails 3.0.1 with prawn-0.11.1.pre

I just did some basic tests to see if I can get Prawn to create a simple table that includes some formatted text:

data = ["Cell 1", formatted_text([{:text => "Cell 2"}])], 
       ["Cell 3","Cell 4"]
table(data)
render

The PDF renders like this

Cell 2
[Cell 1][      ]
[Cell 3][Cell 4]

(a nice table but with the text "Cell 2" outside the table)

My goal is to get the formatted text "Cell 2" inside Cell #2...

How should I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ヤ经典坏疍 2024-10-08 18:42:46

formatted_text 不返回格式化文本,而是呈现它。所以,当
您在为table“Cell 2”构建数据时调用formatted_text
在表格之前呈现,第 1 行第 2 列的单元格是
空的。我想你想把 Prawn::Table:: Cell::Text 对象
您进行 formatted_text 调用的位置。如果Prawn::Table::Cell::Text
不支持你需要的一切,那么你可能不得不做你的
Prawn::Table::Cell 的子类并手动完成这一切。

formatted_text doesn't return formatted text, it renders it. So, when
you call formatted_text while building your data for table, "Cell 2"
is rendered before the table and the cell at row 1 and column 2 is
empty. I think you want to put at Prawn::Table::Cell::Text object
where you have your formatted_text call. If Prawn::Table::Cell::Text
doesn't support everything you need then you'll probably have to make your
subclass of Prawn::Table::Cell and do it all by hand.

宫墨修音 2024-10-08 18:42:46

至少在大虾0.12中,我可以这样做:

table_data = 
  [[Prawn::Table::Cell::Text.new( pdf, [0,0], :content => "<b>Bold!</b>",
                                              :inline_format => true),
    Prawn::Table::Cell::Text.new( pdf, [0,0], :content => txt )
  ]]

  pdf.table(table_data)

At least in prawn 0.12, I can do:

table_data = 
  [[Prawn::Table::Cell::Text.new( pdf, [0,0], :content => "<b>Bold!</b>",
                                              :inline_format => true),
    Prawn::Table::Cell::Text.new( pdf, [0,0], :content => txt )
  ]]

  pdf.table(table_data)
柒夜笙歌凉 2024-10-08 18:42:46

您可以将内联样式格式与单元格样式选项 inline_format结合使用:

table [["Just <font size='18'>some</font> <b><i>inline</i></b>", "", ""],
         ["<color rgb='FF00FF'>styles</color> being applied here", "", ""]],
         :cell_style => { :inline_format => true }

请参阅:https://github.com/practicingruby/prawn/blob/stable/manual/table/cell_text.rb#L28

You can use inline style format with cell style option inline_format:

table [["Just <font size='18'>some</font> <b><i>inline</i></b>", "", ""],
         ["<color rgb='FF00FF'>styles</color> being applied here", "", ""]],
         :cell_style => { :inline_format => true }

See: https://github.com/practicingruby/prawn/blob/stable/manual/table/cell_text.rb#L28

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文