如何在虾表中设置字体大小?

时间:2022-04-21 21:14:38

How do I set the font size in a PDF table using the prawn gem?

如何使用prawn gem在PDF表格中设置字体大小?

When I call prawn like the following:

当我给大虾打电话时如下:

pdf = Prawn::Document.new(:page_size => 'LEGAL', :page_layout => :landscape)
pdf.table data, 
    :header => true,
    :column_widths => widths,
    :font_size => 7,
    :row_colors => ["EEEEEE", "FFFFFF"]

I get an NoMethodError

我得到一个NoMethodError

undefined method `font_size=' for #<Prawn::Table:0x6ce37ea4>

When I remove the ":font_size => 7", it renders but I get an undesirable font size.

当我删除“:font_size => 7”时,它呈现但我得到了一个不受欢迎的字体大小。

I am using prawn 0.12.0, ruby 1.9.3p194, and Rails 3.1.9.

我使用的是对虾0.12.0,ruby 1.9.3p194和Rails 3.1.9。

3 个解决方案

#1


16  

You have to apply the size property to the cell text directly. Here is how to do this:

您必须直接将size属性应用于单元格文本。以下是如何执行此操作:

pdf.table data, 
  :header => true,
  :column_widths => widths,
  :cell_style => { size: 7 },
  :row_colors => ["EEEEEE", "FFFFFF"]

Source: http://prawn.majesticseacreature.com/manual.pdf

#2


2  

:font_size => 7 not works.

:font_size => 7不起作用。

The correct way is :size => 7

正确的方法是:size => 7

    pdf = Prawn::Document.new(:page_size => 'LEGAL', :page_layout => :landscape)
    pdf.table data, 
    :header => true,
    :column_widths => widths,
    :size => 7,
    :row_colors => ["EEEEEE", "FFFFFF"]

#3


0  

pdf.table(data) do
  style row(0), :font_size => 7
end

I believe for 0.12.0 you could also use something like this:

我相信0.12.0你也可以使用这样的东西:

table([[ {:font_size => 7 } ]])

https://github.com/prawnpdf/prawn/wiki/CHANGELOG

#1


16  

You have to apply the size property to the cell text directly. Here is how to do this:

您必须直接将size属性应用于单元格文本。以下是如何执行此操作:

pdf.table data, 
  :header => true,
  :column_widths => widths,
  :cell_style => { size: 7 },
  :row_colors => ["EEEEEE", "FFFFFF"]

Source: http://prawn.majesticseacreature.com/manual.pdf

#2


2  

:font_size => 7 not works.

:font_size => 7不起作用。

The correct way is :size => 7

正确的方法是:size => 7

    pdf = Prawn::Document.new(:page_size => 'LEGAL', :page_layout => :landscape)
    pdf.table data, 
    :header => true,
    :column_widths => widths,
    :size => 7,
    :row_colors => ["EEEEEE", "FFFFFF"]

#3


0  

pdf.table(data) do
  style row(0), :font_size => 7
end

I believe for 0.12.0 you could also use something like this:

我相信0.12.0你也可以使用这样的东西:

table([[ {:font_size => 7 } ]])

https://github.com/prawnpdf/prawn/wiki/CHANGELOG