2012-09-10 8 views
7

Estoy tratando de generar una tabla simple en ruby ​​con gambas pdf.Prawn PDF table mixed formats

Necesito que el texto en una celda sea negrita, y que algunos no sean negritas. Por ejemplo:

Example table ahora siguiendo algunos ejemplos, tengo la tabla básica de representación con este código:

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

pero puedo ver absolutamente ninguna manera de insertar más texto en la primera celda con un formato diferente . (En este caso quiero que se desmarque)

¿Alguien sabe cómo lograr esto?

Gracias por cualquier ayuda

Respuesta

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 

También pueden hacer

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 de gambas apoya <b>, <i>, <u>, <strikethrough>, <sub>, <sup>, <font>, <color> and <link>

+0

Gracias, justo lo que estaba buscando. ¡Estaba preocupado de que esto degeneraría en células anidadas invisibles! – Chris