gpt4 book ai didi

ruby - Prawn PDF表格混合格式

转载 作者:数据小太阳 更新时间:2023-10-29 06:55:52 33 4
gpt4 key购买 nike

我正在尝试使用 prawn pdf 在 ruby​​ 中生成一个简单的表格。

我需要单元格中的一些文本是粗体,而一些不是粗体。例如:

Example table现在按照一些示例,我使用以下代码进行了基本的表格渲染:

pdf.table([
["1. Row example text", "433"],
["2. Row example text", "2343"],
["3. Row example text", "342"],
["4. Row example text", "36"]], :width => 500, :cell_style => {
:font_style => :bold})

但我完全看不出有什么办法可以用不同的格式将更多文本插入到第一个单元格中。 (在这种情况下,我希望它不加粗)

有谁知道如何做到这一点?

感谢您的帮助

最佳答案

Prawn::Document.generate("test.pdf") do |pdf|
table_data = [[Prawn::Table::Cell::Text.new( pdf, [0,0], :content => "<b>1. Row example text</b> \n\nExample Text Not Bolded", :inline_format => true), "433"],
[Prawn::Table::Cell::Text.new( pdf, [0,0], :content => "<b>2. Row example text</b>", :inline_format => true), "2343"],
[Prawn::Table::Cell::Text.new( pdf, [0,0], :content => "<b>3. Row example text</b>", :inline_format => true), "342"],
[Prawn::Table::Cell::Text.new( pdf, [0,0], :content => "<b>4. Row example text</b>", :inline_format => true), "36"]]

pdf.table(table_data,:width => 500)
end

你也可以这样做

Prawn::Document.generate("test.pdf") do |pdf|
table_data = [["<b>1. Row example text</b>\n\nExample Text Not Bolded", "<b>433<b>"],
["<b>2. Row example text</b>", "<b>2343</b>"],
["<i>3. Row example text</i>", "<i>342</i>"],
["<b>4. Row example text</b>", "<sub>36</sub>"]]

pdf.table(table_data, :width => 500, :cell_style => { :inline_format => true })
end

Prawn的inline_format支持<b>, <i>, <u>, <strikethrough>, <sub>, <sup>, <font>, <color> and <link>

关于ruby - Prawn PDF表格混合格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12355503/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com