Is it possible to add a background color to a bounding_box in Prawn?
bounding_box([100, cursor], width: 80, height: 20) do
pad_top(7) { text "THIS IS TEXT", size: 8, align: :center }
stroke_bounds
end
Ive tried adding this to the bounding_box block
background_color: "CCCCCC"
Ive tried adding this inside the block
fill_color "CCCCCC"
background_color "CCCCCC"
Nothing seems to work with a bounding_box
Here the code
bounding_box([200,cursor], :width => 350, :height => 80) do
stroke_color 'FFFFFF'
stroke_bounds
stroke do
stroke_color 'FFFF00'
fill_color '36DA5C'
fill_and_stroke_rounded_rectangle [cursor-80,cursor], 350, 80, 10
fill_color '000000'
end
end
This was discussed 2008 [1] (apparently didn't lead anywhere though), i don't see it mentioned anywhere in the manual [2] either.
As to how it's done: After putting all content into your bounding box, you can obtain the resulting width and height from the bounding box. With that information you can use primitve rectangle drawing to fill it. Afterwards you will have to redraw the content, because by now you will have painted right over it with your rectangle fill.
Hopefully (probably?) there's a better way too, one where you don't need to draw your actual content twice; Make sure to share it with everyone when you come across it!
All the stuff I mentioned in the quick how-to above is beautifully documented in the manual [2]; Good luck!
[1] https://groups.google.com/forum/#!msg/prawn-ruby/6XW54cGy0GA/RdXwL0Zo_Z8J
[2] http://prawn.majesticseacreature.com/manual.pdf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With