虾。样式单元对象

时间:2011-03-25 18:19:48

标签: ruby-on-rails ruby pdf prawn

如何使用最新版本的Prawn构建具有背景颜色和自定义文本的Box?

在之前的prawn版本中我们有

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

with:align,:text_color属性。因此,使用背景颜色,文本对齐中心和自定义文本颜色构建表格单元格很容易。

从github * prawn(0.11.1.pre 8ed4c22)更新到最新版本之后表格:: Cell对象完全改变

http://prawn.majesticseacreature.com/docs/0.10.2/Prawn/Table/Cell.html
https://github.com/sandal/prawn/blob/master/lib/prawn/table/cell.rb

环境

rails: 3.0.5
ruby: 1.9.2

2 个答案:

答案 0 :(得分:6)

我在Prawn邮件列表上提出同样的问题

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

这样做非常容易

  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

答案 1 :(得分:0)

我认为您希望Prawn::Table::Cell::Text具有text_colorbackground_color(继承自Prawn::Table::Cell)方法。您可能需要手动进行水平对齐,但您可以创建自己的Prawn::Table::Cell::TextPrawn::Table::Cell子类来隐藏丑陋的细节。