[ACCEPTED]-Set the font color in prawn-prawn

Accepted answer
Score: 33

Have you tried fill_color? Code below should work:

require "rubygems"
require "prawn" 

Prawn::Document.generate "hello.pdf" do 
  fill_color "0000ff" 
  text "Hello World (in blue)", :at => [200,720], :size => 32 
end

0

Score: 6

if you use any 1.x version (it's only a 2 pre-release as of writing) you can also 1 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
Score: 3

Note that you can also set a CMYK color 1 (in this example 100% key black):

fill_color(0,0,0,100)
Score: 1

Use the color option

text "Red color here", color: 'FF0000'

And the result:

Red color here

With the utmost respect, there 5 is no need to use fill_color as of 2022 because you 4 have to manually set and then unset the 3 color - IMO it's much better to set the 2 color directly via the prawn DSL (domain 1 specific language).

More Related questions