Replies: 5 comments
-
You can do so currently as follows - Prawn::Document.generate("test.pdf") do |pdf|
table_data = [[Prawn::Table::Cell::Text.new( pdf, [0,0], :content => "Red Background", :inline_format => true, :background_color => "ff0000"), "433"],
[Prawn::Table::Cell::Text.new( pdf, [0,0], :content => "Green Background", :inline_format => true, :background_color => "00ff00"), "2343"],
[Prawn::Table::Cell::Text.new( pdf, [0,0], :content => "Blue Background", :inline_format => true, :background_color => "0000ff"), "36"]]
pdf.table(table_data,:width => 500)
end |
Beta Was this translation helpful? Give feedback.
-
I think this is request is still open. I want to highlight characters in a text, not in an inner table. |
Beta Was this translation helpful? Give feedback.
-
I wanted to highlight inline text in a text box. Because this issue was closed without resolving it, I had to resort to ugly hacks that involve exchanging It's all very horrible, but mostly works, so maybe this code is useful for somebody: array = text_formatter.format(translate('disclaimer').gsub("\n", ' '), [])
array = array.map do |item|
item[:styles] = [:highlight] if item[:styles] == [:bold]
item
end
options = {
document: self,
draw_text_callback: ->(text, options) {
if do_highlight?(text) # do_highlight is custom
with_color('ffff00') do # with_color is custom
x_left = options[:at][0] - 2
x_right = options[:at][0] + width_of(text)
y_top = options[:at][1] - 2
y_bottom = options[:at][1] + height_of(text) - 2
fill_polygon([x_left, y_top],
[x_right, y_top],
[x_right, y_bottom],
[x_left, y_bottom])
end
end
draw_text!(text, options)
},
}
box = ::Prawn::Text::Formatted::Box.new(array, options)
box.render |
Beta Was this translation helpful? Give feedback.
-
I'm also irritated that this was closed without being resolved. Maybe there's a secret society of Prawn experts who know how to set text background colors and outsiders are not supposed to know. The lack of documentation on something that should be pretty standard is very very irritating. And yet the manual has plenty of instances with text in boxes with different background colors. So it's clearly something the experts know how to do, but they're not telling us how to do it. |
Beta Was this translation helpful? Give feedback.
-
Try this:
|
Beta Was this translation helpful? Give feedback.
-
I think Prawn needs an inline tag for background color like in this HTML-snippet:
<span style="background: red;">text on red bg</span>
.see: http://stackoverflow.com/questions/17546552/how-to-highlight-text-with-background-in-a-table-with-prawn-prawn-to/17564534?noredirect=1#17564534
Originally I wanted to highlight some characters in an inner table.
Beta Was this translation helpful? Give feedback.
All reactions