2012-09-10 6 views
7

私は、prawn pdfを使って簡単なテーブルを作成しようとしています。Prawn PDFテーブルの混合フォーマット

セルには太字で、太字ではないテキストが必要です。たとえば:今いくつかの例を以下

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

しかし、私は別の形式の最初のセルに複数のテキストを挿入する絶対にない方法を見ることができます。 (この場合はアンボールドしたい)

これを達成する方法は誰にも分かりますか?任意のヘルプ

答えて

19
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 

を行うことができますエビのinline_formatは<b>, <i>, <u>, <strikethrough>, <sub>, <sup>, <font>, <color> and <link>

+0

をサポートしています私が探していただけのものを、ありがとうございます。目に見えないネストされた細胞に堕落するのではないかと心配しました! – Chris

関連する問題