【问题标题】:Prawn PDF table mixed formats大虾PDF表格混合格式
【发布时间】:2012-09-03 13:04:33
【问题描述】:

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

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

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

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})

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

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

感谢您的帮助

【问题讨论】:

    标签: ruby pdf pdf-generation prawn


    【解决方案1】:
    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 支持&lt;b&gt;, &lt;i&gt;, &lt;u&gt;, &lt;strikethrough&gt;, &lt;sub&gt;, &lt;sup&gt;, &lt;font&gt;, &lt;color&gt; and &lt;link&gt;

    【讨论】:

    • 谢谢,正是我想要的。担心这会退化成看不见的嵌套单元格!
    猜你喜欢
    • 1970-01-01
    • 2011-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多