开发者

Prawn. Styling cell object

How I can b开发者_运维知识库uild Box with background color and custom text inside with latest version of Prawn ?

In previous prawn version we had

http://rubydoc.info/gems/prawn-layout/0.8.4/Prawn/Table/Cell

with :align, :text_color attributes. So it was easy to build table cell with background color, text align center and custom text color.

After update to latest version from github * prawn (0.11.1.pre 8ed4c22) Table::Cell object changed completely

http://prawn.majesticseacreature.com/docs/0.10.2/Prawn/Table/Cell.html

https://github.com/sandal/prawn/blob/master/lib/prawn/table/cell.rb

Environment

rails: 3.0.5
ruby: 1.9.2


I ask same question on Prawn mailing list

http://groups.google.com/group/prawn-ruby/browse_thread/thread/7147d92ec6481947

And it was super easy to do it

  pdf.bounding_box(pdf.bounds.top_left, :width => x, :height => y) do
    pdf.cell :content => 'your text', :background_color => 'E8E8D0', :width => x, :height => y, :align => :center, :text_color => "001B76"
    pdf.move_down 4
  end


I think you want Prawn::Table::Cell::Text, that has text_color and background_color (inherited from Prawn::Table::Cell) methods. You might have to do the horizontal alignment by hand but you could make your own subclass of Prawn::Table::Cell::Text or Prawn::Table::Cell to hide the ugly details.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜