2011-11-02 106 views
0

我正在尝试使用标签为使用大虾生成的pdf生成一些样式。但是,似乎有一个错误。使用大虾生成pdf时出错

require 'rubygems' 
require 'prawn' 
require 'prawn/layout' 
require 'prawn/format' 

Prawn::Document.generate "example.pdf" do 
     tags:h1=>{ :font_size => "16pt", :font_weight => :bold } 
     text"<h1>Student Details</h1>" 
end 

我碰到下面的错误 -

/usr/lib/ruby/gems/1.8/gems/prawn-format-0.2.3/lib/prawn/format/text_object.rb:91:in `%': can't convert nil into Float (TypeError) 

任何帮助是极大的赞赏。

干杯!

回答

1

它不应该是:

tags[:h1] = { :font_size => "16pt", :font_weight => :bold } 

同时请注意:

由于虾0.7,对虾格式是完全不支持,并将与虾0.7+版本不 工作。随意分叉和修复,当然是 。

考虑使用从虾方法::文本

http://rubydoc.info/gems/prawn/0.12.0/Prawn/Text

编辑

例如:

require 'rubygems' 
require 'prawn' 

Prawn::Document.generate('font_calculations.pdf') do 
    font "Courier", :size => 16, :style => :bold 
    text "Student details" 
    font "Courier", :size => 12, :style => :normal 
    text "normal text" 
    text "this is normal, <b>but this is bold</b>", :inline_format => true 
    text "normal <font size='18'>bigger</font> normal", :inline_format => true 
end 

这只是这样做的途径之一。

+0

更改标签为[:h1]它仍然给我同样的错误。 – verdure

+0

@verdure虾0.2.3是旧的(又名2008)。任何理由你需要这个版本? – Ernest

+0

我检查了我的Prawn版本并将其更新到0.12.0,但错误仍然存​​在。 – verdure