Set the font color in prawn
Im using prawn to gen开发者_C百科erate a PDF output in a rails app. How do i change the color of the outputted text?
Have you tried fill_color
? Code below should work:
require "rubygems"
require "prawn"
Prawn::Document.generate "hello.pdf" do
fill_color "0000ff"
text_box "Hello World (in blue)", :at => [200,720], :size => 32
end
if you use any 1.x version (it's only a pre-release as of writing) you can also use:
Gem install:
$ gem install prawn --pre
Code:
require "rubygems"
require "prawn"
Prawn::Document.generate "hello.pdf" do
text "Hello World (in blue)", :color => "0000ff", :size => 32
end
Note that you can also set a CMYK color (in this example 100% key black):
fill_color(0,0,0,100)
Use the color
option
text "Red color here", color: 'FF0000'
And the result:
With the utmost respect, there is no need to use fill_color
as of 2022 because you have to manually set and then unset the color - IMO it's much better to set the color directly via the prawn DSL (domain specific language).
精彩评论