开发者

Draw formatted text inside a Table/Cell with Prawn

I am running Rails 3.0.1 with prawn-0.11.1.p开发者_如何学Pythonre

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?


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜