【问题标题】:Error generating pdf using prawn使用大虾生成pdf时出错
【发布时间】:2011-11-02 10:29:13
【问题描述】:

我正在尝试使用标签为使用 prawn 生成的 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)

非常感谢任何帮助。

干杯!!

【问题讨论】:

    标签: ruby pdf prawn


    【解决方案1】:

    不应该是:

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

    ?

    另外请注意:

    从 Prawn 0.7 开始,完全不支持 prawn-format,并且不会 使用 Prawn 0.7+ 版本。随意分叉和修复, 当然。

    考虑使用 Prawn::Text 中的方法

    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
    

    这只是众多方法之一。

    【讨论】:

    • @verdure Prawn 0.2.3 有点旧(又名 2008 年)。有什么理由需要这个版本?
    • 我已经检查了我的Prawn版本并将其更新到0.12.0,但错误仍然存​​在。
    • @verdure 正如我所说的虾格式不受支持,tags 是其中的一部分。查看更新。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-23
    相关资源
    最近更新 更多