Reputation: 3341
I am trying to use tags to give some styling for a pdf being generated using prawn. But, there seems to be an error.
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
I get the following error -
/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)
Any help is greatly appreciated.
Cheers!!
Upvotes: 0
Views: 826
Reputation: 8829
Shouldn't it be:
tags[:h1] = { :font_size => "16pt", :font_weight => :bold }
?
Also please note that:
As of Prawn 0.7, prawn-format is completely unsupported, and will not work with versions of Prawn 0.7+. Feel free to fork and fix, of course.
Consider using methods from Prawn::Text
http://rubydoc.info/gems/prawn/0.12.0/Prawn/Text
EDIT
For example:
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
That's just one of many ways of doing this.
Upvotes: 1