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