Font color for a text_box

92 views
Skip to first unread message

connor

unread,
Jan 26, 2016, 2:54:04 PM1/26/16
to Prawn
How do I set the font color for a text box?

the rails controller the generates the pdf has the following code...

pdf = Prawn::Document.new(page_size:  "A4",margin: [0,0,0,0])
        pdf.font_families.update("Century" => {
            :normal => "#{Rails.root}/app/assets/fonts/century_normal.ttf",
            :bold => "#{Rails.root}/app/assets/fonts/century_bold.ttf"
          })
        pdf.font "Century"
        # pdf.fill_color "0000ff"
        pdf.text_box "Mr Nobody", :at => [100, 600], :align => :center, size: 25, style: :bold, color: '#3172bd'

       send_data pdf.render, filename: 'report.pdf', type: 'application/pdf'


which generates the correct font but not the color?

Alexander Mankuta

unread,
Jan 26, 2016, 3:01:49 PM1/26/16
to Prawn
Prawn::Document.generate("hello.pdf") do
  fill_color '3172bd'
  text_box "Mr Nobody", at: [100, 600], align: :center, size: 25, style: :bold
end


You don't need to put in the hash symbol into color. Just 6 digits of hex color.

connor

unread,
Jan 26, 2016, 3:26:38 PM1/26/16
to Prawn
I tried that but it just throws an error "undefined method `fill_color'"

connor

unread,
Jan 26, 2016, 3:35:11 PM1/26/16
to Prawn
sorry that works,
I hadn't changed it to  "fill_color '3172bd'"
Reply all
Reply to author
Forward
0 new messages